Add almost full option support

This commit is contained in:
Zachary Yedidia
2019-01-13 21:06:58 -05:00
parent 163ca36eeb
commit 7a20c2db76
16 changed files with 285 additions and 279 deletions

View File

@@ -1009,6 +1009,7 @@ func (h *BufHandler) Escape() bool {
// Quit this will close the current tab or view that is open
func (h *BufHandler) Quit() bool {
quit := func() {
h.Buf.Close()
if len(MainTab().Panes) > 1 {
h.Unsplit()
} else if len(Tabs.List) > 1 {

View File

@@ -6,7 +6,6 @@ import (
"syscall"
"github.com/zyedidia/micro/cmd/micro/screen"
"github.com/zyedidia/micro/cmd/micro/util"
)
// Suspend sends micro to the background. This is the same as pressing CtrlZ in most unix programs.
@@ -19,7 +18,7 @@ func (*BufHandler) Suspend() bool {
pid := syscall.Getpid()
err := syscall.Kill(pid, syscall.SIGSTOP)
if err != nil {
util.TermMessage(err)
screen.TermMessage(err)
}
screen.TempStart(screenb)

View File

@@ -10,7 +10,7 @@ import (
"github.com/flynn/json5"
"github.com/zyedidia/micro/cmd/micro/config"
"github.com/zyedidia/micro/cmd/micro/util"
"github.com/zyedidia/micro/cmd/micro/screen"
"github.com/zyedidia/tcell"
)
@@ -24,13 +24,13 @@ func InitBindings() {
if _, e := os.Stat(filename); e == nil {
input, err := ioutil.ReadFile(filename)
if err != nil {
util.TermMessage("Error reading bindings.json file: " + err.Error())
screen.TermMessage("Error reading bindings.json file: " + err.Error())
return
}
err = json5.Unmarshal(input, &parsed)
if err != nil {
util.TermMessage("Error reading bindings.json:", err.Error())
screen.TermMessage("Error reading bindings.json:", err.Error())
}
}
@@ -45,7 +45,7 @@ func InitBindings() {
func BindKey(k, v string) {
event, ok := findEvent(k)
if !ok {
util.TermMessage(k, "is not a bindable event")
screen.TermMessage(k, "is not a bindable event")
}
switch e := event.(type) {

View File

@@ -5,7 +5,7 @@ import (
"github.com/zyedidia/micro/cmd/micro/buffer"
"github.com/zyedidia/micro/cmd/micro/display"
"github.com/zyedidia/micro/cmd/micro/util"
"github.com/zyedidia/micro/cmd/micro/screen"
"github.com/zyedidia/tcell"
)
@@ -28,7 +28,7 @@ func BufMapKey(k Event, action string) {
BufKeyStrings[k] = action
BufKeyBindings[k] = f
} else {
util.TermMessage("Error:", action, "does not exist")
screen.TermMessage("Error:", action, "does not exist")
}
}
@@ -43,7 +43,7 @@ func BufMapMouse(k MouseEvent, action string) {
// ensure we don't double bind a key
delete(BufMouseBindings, k)
} else {
util.TermMessage("Error:", action, "does not exist")
screen.TermMessage("Error:", action, "does not exist")
}
}
@@ -268,6 +268,9 @@ func (h *BufHandler) HSplitBuf(buf *buffer.Buffer) {
MainTab().Resize()
MainTab().SetActive(len(MainTab().Panes) - 1)
}
func (h *BufHandler) Close() {
h.Buf.Close()
}
// BufKeyActions contains the list of all possible key actions the bufhandler could execute
var BufKeyActions = map[string]BufKeyAction{

View File

@@ -257,12 +257,86 @@ func (h *BufHandler) NewTabCmd(args []string) {
}
}
func SetGlobalOption(option, value string) error {
if _, ok := config.GlobalSettings[option]; !ok {
return config.ErrInvalidOption
}
nativeValue, err := config.GetNativeValue(option, config.GlobalSettings[option], value)
if err != nil {
return err
}
config.GlobalSettings[option] = nativeValue
if option == "colorscheme" {
// LoadSyntaxFiles()
config.InitColorscheme()
for _, b := range buffer.OpenBuffers {
b.UpdateRules()
}
}
// TODO: info and keymenu option change
// if option == "infobar" || option == "keymenu" {
// for _, tab := range tabs {
// tab.Resize()
// }
// }
if option == "mouse" {
if !nativeValue.(bool) {
screen.Screen.DisableMouse()
} else {
screen.Screen.EnableMouse()
}
}
for _, b := range buffer.OpenBuffers {
b.SetOption(option, value)
}
config.WriteSettings(config.ConfigDir + "/settings.json")
return nil
}
// SetCmd sets an option
func (h *BufHandler) SetCmd(args []string) {
if len(args) < 2 {
InfoBar.Error("Not enough arguments")
return
}
option := args[0]
value := args[1]
err := SetGlobalOption(option, value)
if err == config.ErrInvalidOption {
err := h.Buf.SetOption(option, value)
if err != nil {
InfoBar.Error(err)
}
} else if err != nil {
InfoBar.Error(err)
}
}
// SetLocalCmd sets an option local to the buffer
func (h *BufHandler) SetLocalCmd(args []string) {
if len(args) < 2 {
InfoBar.Error("Not enough arguments")
return
}
option := args[0]
value := args[1]
err := h.Buf.SetOption(option, value)
if err != nil {
InfoBar.Error(err)
}
}
// ShowCmd shows the value of the given option
@@ -341,6 +415,8 @@ func (h *BufHandler) TermCmd(args []string) {
h.AddTab()
i = 0
id = MainTab().Panes[0].ID()
} else {
MainTab().Panes[i].Close()
}
v := h.GetView()

View File

@@ -11,6 +11,7 @@ type Pane interface {
display.Window
ID() uint64
Name() string
Close()
}
type EditPane struct {

View File

@@ -31,7 +31,10 @@ func (t *TermHandler) ID() uint64 {
return t.id
}
func (t *TermHandler) Close() {}
func (t *TermHandler) Quit() {
t.Close()
if len(MainTab().Panes) > 1 {
t.Unsplit()
} else if len(Tabs.List) > 1 {