Skip to content

Commit fc3ed74

Browse files
Merge branch 'master' into dev
2 parents 1e5bcdb + 41b912b commit fc3ed74

File tree

13 files changed

+100
-58
lines changed

13 files changed

+100
-58
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ You can also check out the website for Micro at https://micro-editor.github.io.
7878
- Syntax highlighting for over [130 languages](runtime/syntax).
7979
- Color scheme support.
8080
- By default, micro comes with 16, 256, and true color themes.
81-
- True color support (set the `MICRO_TRUECOLOR` environment variable to 1 to enable it).
81+
- True color support.
8282
- Copy and paste with the system clipboard.
8383
- Small and simple.
8484
- Easily configurable.

cmd/micro/micro.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,6 @@ func main() {
374374
action.InitBindings()
375375
action.InitCommands()
376376

377-
err = config.InitColorscheme()
378-
if err != nil {
379-
screen.TermMessage(err)
380-
}
381-
382377
err = config.RunPluginFn("preinit")
383378
if err != nil {
384379
screen.TermMessage(err)
@@ -407,6 +402,11 @@ func main() {
407402
screen.TermMessage(err)
408403
}
409404

405+
err = config.InitColorscheme()
406+
if err != nil {
407+
screen.TermMessage(err)
408+
}
409+
410410
if clipErr != nil {
411411
log.Println(clipErr, " or change 'clipboard' option")
412412
}

internal/action/actions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,11 +1909,11 @@ func (h *BufPane) ClearInfo() bool {
19091909
return true
19101910
}
19111911

1912-
// ForceQuit closes the current tab or view even if there are unsaved changes
1912+
// ForceQuit closes the tab or view even if there are unsaved changes
19131913
// (no prompt)
19141914
func (h *BufPane) ForceQuit() bool {
19151915
h.Buf.Close()
1916-
if len(MainTab().Panes) > 1 {
1916+
if len(h.tab.Panes) > 1 {
19171917
h.Unsplit()
19181918
} else if len(Tabs.List) > 1 {
19191919
Tabs.RemoveTab(h.splitID)

internal/action/bufpane.go

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,16 @@ func (h *BufPane) ResizePane(size int) {
321321
}
322322

323323
// PluginCB calls all plugin callbacks with a certain name and displays an
324-
// error if there is one and returns the aggregate boolean response
325-
func (h *BufPane) PluginCB(cb string) bool {
326-
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, luar.New(ulua.L, h))
327-
if err != nil {
328-
screen.TermMessage(err)
324+
// error if there is one and returns the aggregate boolean response.
325+
// The bufpane is passed as the first argument to the callbacks,
326+
// optional args are passed as the next arguments.
327+
func (h *BufPane) PluginCB(cb string, args ...interface{}) bool {
328+
largs := []lua.LValue{luar.New(ulua.L, h)}
329+
for _, a := range args {
330+
largs = append(largs, luar.New(ulua.L, a))
329331
}
330-
return b
331-
}
332332

333-
// PluginCBRune is the same as PluginCB but also passes a rune to the plugins
334-
func (h *BufPane) PluginCBRune(cb string, r rune) bool {
335-
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
333+
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, largs...)
336334
if err != nil {
337335
screen.TermMessage(err)
338336
}
@@ -559,7 +557,7 @@ func (h *BufPane) execAction(action BufAction, name string, te *tcell.EventMouse
559557
h.Buf.HasSuggestions = false
560558
}
561559

562-
if !h.PluginCB("pre" + name) {
560+
if !h.PluginCB("pre"+name, te) {
563561
return false
564562
}
565563

@@ -570,7 +568,7 @@ func (h *BufPane) execAction(action BufAction, name string, te *tcell.EventMouse
570568
case BufMouseAction:
571569
success = a(h, te)
572570
}
573-
success = success && h.PluginCB("on"+name)
571+
success = success && h.PluginCB("on"+name, te)
574572

575573
if _, ok := MultiActions[name]; ok {
576574
if recordingMacro {
@@ -626,7 +624,7 @@ func (h *BufPane) DoRuneInsert(r rune) {
626624
// Insert a character
627625
h.Buf.SetCurCursor(c.Num)
628626
h.Cursor = c
629-
if !h.PluginCBRune("preRune", r) {
627+
if !h.PluginCB("preRune", string(r)) {
630628
continue
631629
}
632630
if c.HasSelection() {
@@ -645,35 +643,35 @@ func (h *BufPane) DoRuneInsert(r rune) {
645643
curmacro = append(curmacro, r)
646644
}
647645
h.Relocate()
648-
h.PluginCBRune("onRune", r)
646+
h.PluginCB("onRune", string(r))
649647
}
650648
}
651649

652650
// VSplitIndex opens the given buffer in a vertical split on the given side.
653651
func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane {
654652
e := NewBufPaneFromBuf(buf, h.tab)
655-
e.splitID = MainTab().GetNode(h.splitID).VSplit(right)
656-
currentPaneIdx := MainTab().GetPane(h.splitID)
653+
e.splitID = h.tab.GetNode(h.splitID).VSplit(right)
654+
currentPaneIdx := h.tab.GetPane(h.splitID)
657655
if right {
658656
currentPaneIdx++
659657
}
660-
MainTab().AddPane(e, currentPaneIdx)
661-
MainTab().Resize()
662-
MainTab().SetActive(currentPaneIdx)
658+
h.tab.AddPane(e, currentPaneIdx)
659+
h.tab.Resize()
660+
h.tab.SetActive(currentPaneIdx)
663661
return e
664662
}
665663

666664
// HSplitIndex opens the given buffer in a horizontal split on the given side.
667665
func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane {
668666
e := NewBufPaneFromBuf(buf, h.tab)
669-
e.splitID = MainTab().GetNode(h.splitID).HSplit(bottom)
670-
currentPaneIdx := MainTab().GetPane(h.splitID)
667+
e.splitID = h.tab.GetNode(h.splitID).HSplit(bottom)
668+
currentPaneIdx := h.tab.GetPane(h.splitID)
671669
if bottom {
672670
currentPaneIdx++
673671
}
674-
MainTab().AddPane(e, currentPaneIdx)
675-
MainTab().Resize()
676-
MainTab().SetActive(currentPaneIdx)
672+
h.tab.AddPane(e, currentPaneIdx)
673+
h.tab.Resize()
674+
h.tab.SetActive(currentPaneIdx)
677675
return e
678676
}
679677

internal/config/colorscheme.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func InitColorscheme() error {
5555
c, err := LoadDefaultColorscheme()
5656
if err == nil {
5757
Colorscheme = c
58+
} else {
59+
// The colorscheme setting seems broken (maybe because we have not validated
60+
// it earlier, see comment in verifySetting()). So reset it to the default
61+
// colorscheme and try again.
62+
GlobalSettings["colorscheme"] = DefaultGlobalOnlySettings["colorscheme"]
63+
if c, err2 := LoadDefaultColorscheme(); err2 == nil {
64+
Colorscheme = c
65+
}
5866
}
5967

6068
return err

internal/config/settings.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var optionValidators = map[string]optionValidator{
3636
"scrollmargin": validateNonNegativeValue,
3737
"scrollspeed": validateNonNegativeValue,
3838
"tabsize": validatePositiveValue,
39+
"truecolor": validateChoice,
3940
}
4041

4142
// a list of settings with pre-defined choices
@@ -46,6 +47,7 @@ var OptionChoices = map[string][]string{
4647
"matchbracestyle": {"underline", "highlight"},
4748
"multiopen": {"tab", "hsplit", "vsplit"},
4849
"reload": {"prompt", "auto", "disabled"},
50+
"truecolor": {"auto", "on", "off"},
4951
}
5052

5153
// a list of settings that can be globally and locally modified and their
@@ -100,6 +102,7 @@ var defaultCommonSettings = map[string]interface{}{
100102
"tabmovement": false,
101103
"tabsize": float64(4),
102104
"tabstospaces": false,
105+
"truecolor": "auto",
103106
"useprimary": true,
104107
"wordwrap": false,
105108
"wrapindent": float64(-1),
@@ -274,6 +277,12 @@ func verifySetting(option string, value interface{}, def interface{}) error {
274277
return fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", option, valType, def, defType)
275278
}
276279

280+
if option == "colorscheme" {
281+
// Plugins are not initialized yet, so do not verify if the colorscheme
282+
// exists yet, since the colorscheme may be added by a plugin later.
283+
return nil
284+
}
285+
277286
if err := OptionIsValid(option, value); err != nil {
278287
return err
279288
}

internal/screen/screen.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,13 @@ func Init() error {
188188
drawChan = make(chan bool, 8)
189189

190190
// Should we enable true color?
191-
truecolor := os.Getenv("MICRO_TRUECOLOR") == "1"
192-
193-
if !truecolor {
191+
truecolor := config.GetGlobalOption("truecolor").(string)
192+
if truecolor == "on" || (truecolor == "auto" && os.Getenv("MICRO_TRUECOLOR") == "1") {
193+
os.Setenv("TCELL_TRUECOLOR", "enable")
194+
} else if truecolor == "off" {
194195
os.Setenv("TCELL_TRUECOLOR", "disable")
196+
} else {
197+
// For "auto", tcell already autodetects truecolor by default
195198
}
196199

197200
var oldTerm string

runtime/help/colors.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ color support comes in three flavors.
4747
displaying any colorscheme, but it should be noted that the user-configured
4848
16-color palette is ignored when using true-color mode (this means the
4949
colors while using the terminal emulator will be slightly off). Not all
50-
terminals support true color but at this point most do. True color
51-
support in micro is off by default but can be enabled by setting the
52-
environment variable `MICRO_TRUECOLOR` to 1. In addition your terminal
53-
must support it (usually indicated by setting `$COLORTERM` to `truecolor`).
50+
terminals support true color but at this point most do (see below).
5451
True-color colorschemes in micro typically end with `-tc`, such as
5552
`solarized-tc`, `atom-dark`, `material-tc`, etc... If true color is not
5653
enabled but a true color colorscheme is used, micro will do its best to
@@ -84,11 +81,12 @@ These may vary widely based on the 16 colors selected for your terminal.
8481

8582
### True color
8683

87-
True color requires your terminal to support it. This means that the
88-
environment variable `COLORTERM` should have the value `truecolor`, `24bit`,
89-
or `24-bit`. In addition, to enable true color in micro, the environment
90-
variable `MICRO_TRUECOLOR` must be set to 1. Note that you have to create
91-
and set this variable yourself.
84+
Micro enables true color support by default as long as it detects that the
85+
terminal supports it (which is usually indicated by the environment variable
86+
`COLORTERM` being set to `truecolor`, `24bit` or `24-bit`). You can also force
87+
enabling it unconditionally by setting the option `truecolor` to `on` (or
88+
alternatively by setting the environment variable `MICRO_TRUECOLOR` to 1, which
89+
is supported for backward compatibility).
9290

9391
* `solarized-tc`: this is the solarized colorscheme for true color.
9492
* `atom-dark`: this colorscheme is based off of Atom's "dark" colorscheme.

runtime/help/options.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,19 @@ Here are the available options:
474474

475475
default value: `false`
476476

477+
* `truecolor`: controls whether micro will use true colors (24-bit colors) when
478+
using a colorscheme with true colors, such as `solarized-tc` or `atom-dark`.
479+
* `auto`: enable usage of true color if micro detects that it is supported by
480+
the terminal, otherwise disable it.
481+
* `on`: force usage of true color even if micro does not detect its support
482+
by the terminal (of course this is not guaranteed to work well unless the
483+
terminal actually supports true color).
484+
* `off`: disable true color usage.
485+
486+
Note: The change will take effect after the next start of `micro`.
487+
488+
default value: `auto`
489+
477490
* `useprimary` (only useful on unix): defines whether or not micro will use the
478491
primary clipboard to copy selections in the background. This does not affect
479492
the normal clipboard using `Ctrl-c` and `Ctrl-v`.

runtime/plugins/comment/help/comment.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Or in your `settings.json`:
9696
}
9797
```
9898

99-
`commenttype` was the previous option name that was replaced by `comment.type`.
100-
101-
While `commenttype` is still supported, we recommend switching to `comment.type` instead as
102-
`commenttype` can get deprecated in the future.
99+
`commenttype` (without the dot) is the legacy option that is
100+
superseded by `comment.type`. `commenttype` is still supported
101+
but deprecated.
102+
**Use `comment.type` instead.**

0 commit comments

Comments
 (0)