chore: import official kitty sources from upstream

Bring the kovidgoyal/kitty codebase in as the base of FWS-Kitty,
vendored at upstream commit 91fb38a without its git history.
This commit is contained in:
BlackAngelTV committed 2026-11-04 11:20:47 +01:00
commit 7e7d249099
1134 files changed
+433629

No files matched your search

View File
Whitespace-only changes.
+99
View File
@@ -0,0 +1,99 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package themes
import (
"fmt"
"github.com/kovidgoyal/kitty/tools/themes"
"github.com/kovidgoyal/kitty/tools/utils"
"github.com/kovidgoyal/kitty/tools/wcswidth"
)
var _ = fmt.Print
type ThemesList struct {
themes, all_themes *themes.Themes
current_search string
display_strings []string
widths []int
max_width, current_idx int
}
func (self *ThemesList) Len() int {
if self.themes == nil {
return 0
}
return self.themes.Len()
}
func (self *ThemesList) Next(delta int, allow_wrapping bool) bool {
if len(self.display_strings) == 0 {
return false
}
idx := self.current_idx + delta
if !allow_wrapping && (idx < 0 || idx > self.Len()) {
return false
}
for idx < 0 {
idx += self.Len()
}
self.current_idx = idx % self.Len()
return true
}
func limit_lengths(text string) string {
t, _ := wcswidth.TruncateToVisualLengthWithWidth(text, 31)
if len(t) >= len(text) {
return text
}
return t + "…"
}
func (self *ThemesList) UpdateThemes(themes *themes.Themes) {
self.themes, self.all_themes = themes, themes
if self.current_search != "" {
self.themes = self.all_themes.Copy()
self.display_strings = utils.Map(limit_lengths, self.themes.ApplySearch(self.current_search))
} else {
self.display_strings = utils.Map(limit_lengths, self.themes.Names())
}
self.widths = utils.Map(wcswidth.Stringwidth, self.display_strings)
self.max_width = utils.Max(0, self.widths...)
self.current_idx = 0
}
func (self *ThemesList) UpdateSearch(query string) bool {
if query == self.current_search || self.all_themes == nil {
return false
}
self.current_search = query
self.UpdateThemes(self.all_themes)
return true
}
type Line struct {
text string
width int
is_current bool
}
func (self *ThemesList) Lines(num_rows int) []Line {
if num_rows < 1 {
return nil
}
ans := make([]Line, 0, len(self.display_strings))
before_num := utils.Min(self.current_idx, num_rows-1)
start := self.current_idx - before_num
for i := start; i < utils.Min(start+num_rows, len(self.display_strings)); i++ {
ans = append(ans, Line{self.display_strings[i], self.widths[i], i == self.current_idx})
}
return ans
}
func (self *ThemesList) CurrentTheme() *themes.Theme {
if self.themes == nil {
return nil
}
return self.themes.At(self.current_idx)
}
+147
View File
@@ -0,0 +1,147 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package themes
import (
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"time"
"github.com/kovidgoyal/kitty/tools/cli"
"github.com/kovidgoyal/kitty/tools/themes"
"github.com/kovidgoyal/kitty/tools/tui/loop"
"github.com/kovidgoyal/kitty/tools/utils"
)
var _ = fmt.Print
func complete_themes(completions *cli.Completions, word string, arg_num int) {
themes.CompleteThemes(completions, word, arg_num)
}
func non_interactive(opts *Options, theme_name string) (rc int, err error) {
themes, closer, err := themes.LoadThemes(time.Duration(opts.CacheAge * float64(time.Hour*24)))
if err != nil {
return 1, err
}
defer closer.Close()
theme := themes.ThemeByName(theme_name)
if theme == nil {
theme_name = strings.ReplaceAll(theme_name, `\`, ``)
theme = themes.ThemeByName(theme_name)
if theme == nil {
return 1, fmt.Errorf("No theme named: %s", theme_name)
}
}
if opts.DumpTheme {
code, err := theme.Code()
if err != nil {
return 1, err
}
fmt.Println(code)
} else {
err = theme.SaveInConf(utils.ConfigDir(), opts.ReloadIn, opts.ConfigFileName)
if err != nil {
return 1, err
}
}
return
}
func main(_ *cli.Command, opts *Options, args []string) (rc int, err error) {
if len(args) > 1 {
args = []string{strings.Join(args, ` `)}
}
if len(args) == 1 {
return non_interactive(opts, args[0])
}
lp, err := loop.New()
if err != nil {
return 1, err
}
cv := utils.NewCachedValues("themes", &CachedData{Category: "All"})
h := &handler{lp: lp, opts: opts, cached_data: cv.Load()}
defer cv.Save()
lp.OnInitialize = func() (string, error) {
lp.AllowLineWrapping(false)
lp.SetWindowTitle(`Choose a theme for kitty`)
h.initialize()
return "", nil
}
lp.OnWakeup = h.on_wakeup
lp.OnFinalize = func() string {
h.finalize()
lp.SetCursorVisible(true)
return ``
}
lp.OnResize = func(_, _ loop.ScreenSize) error {
h.draw_screen()
return nil
}
lp.OnKeyEvent = h.on_key_event
lp.OnText = h.on_text
err = lp.Run()
if err != nil {
return 1, err
}
ds := lp.DeathSignalName()
if ds != "" {
fmt.Println("Killed by signal: ", ds)
lp.KillIfSignalled()
return 1, nil
}
return
}
func EntryPoint(parent *cli.Command) {
create_cmd(parent, main)
}
func parse_theme_metadata() error {
raw, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
paths := utils.Splitlines(utils.UnsafeBytesToString(raw))
ans := make([]*themes.ThemeMetadata, 0, len(paths))
for _, path := range paths {
if path != "" {
metadata, _, err := themes.ParseThemeMetadata(path)
if err != nil {
return err
}
if metadata.Name == "" {
metadata.Name = themes.ThemeNameFromFileName(filepath.Base(path))
}
ans = append(ans, metadata)
}
}
raw, err = json.Marshal(ans)
if err != nil {
return err
}
_, err = os.Stdout.Write(raw)
if err != nil {
return err
}
return nil
}
func ParseEntryPoint(parent *cli.Command) {
parent.AddSubCommand(&cli.Command{
Name: "__parse_theme_metadata__",
Hidden: true,
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
err = parse_theme_metadata()
if err != nil {
rc = 1
}
return
},
})
}
+125
View File
@@ -0,0 +1,125 @@
#!/usr/bin/env python
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
import sys
from kitty.conf.types import Definition
from kitty.simple_cli_definitions import CompletionSpec
definition = Definition(
'!kittens.themes',
)
agr = definition.add_group
egr = definition.end_group
map = definition.add_map
# shortcuts {{{
agr('shortcuts', 'Keyboard shortcuts')
# Browsing mode shortcuts
map(
'Quit',
'quit --allow-fallback=shifted,ascii q quit',
)
map(
'Scroll down',
'scroll_down --allow-fallback=shifted,ascii j scroll_down',
)
map(
'Scroll up',
'scroll_up --allow-fallback=shifted,ascii k scroll_up',
)
map(
'Start search',
'search --allow-fallback=shifted,ascii s search',
)
map(
'Accept theme',
'accept --allow-fallback=shifted,ascii c accept',
)
# Accepting mode shortcuts
map(
'Abort and return to browsing',
'abort --allow-fallback=shifted,ascii a abort',
)
map(
'Place theme file',
'place_theme --allow-fallback=shifted,ascii p place_theme',
)
map(
'Modify config file',
'modify_conf --allow-fallback=shifted,ascii m modify_conf',
)
map(
'Save as dark scheme',
'dark_scheme --allow-fallback=shifted,ascii d dark_scheme',
)
map(
'Save as light scheme',
'light_scheme --allow-fallback=shifted,ascii l light_scheme',
)
map(
'Save as no preference scheme',
'no_preference --allow-fallback=shifted,ascii n no_preference',
)
egr() # }}}
help_text = 'Change the kitty theme. If no theme name is supplied, run interactively, otherwise change the current theme to the specified theme name.'
usage = '[theme name to switch to]'
OPTIONS = """
--cache-age
type=float
default=1
Check for new themes only after the specified number of days. A value of
zero will always check for new themes. A negative value will never check
for new themes, instead raising an error if a local copy of the themes
is not available.
--reload-in
default=parent
choices=none,parent,all
By default, this kitten will signal only the parent kitty instance it is
running in to reload its config, after making changes. Use this option
to instead either not reload the config at all or in all running
kitty instances. Note that if you have config autoreload enabled
in kitty.conf (it is enabled by default) then :code:`parent`
is the same as :code:`all`, since all kitty instances will detect the config
file change and reload automatically.
--dump-theme
type=bool-set
default=false
When running non-interactively, dump the specified theme to STDOUT
instead of changing kitty.conf.
--config-file-name
default=kitty.conf
The name or path to the config file to edit. Relative paths are interpreted
with respect to the kitty config directory. By default the kitty config file,
kitty.conf is edited. This is most useful if you add :code:`include themes.conf`
to your kitty.conf and then have the kitten operate only on :file:`themes.conf`,
allowing :code:`kitty.conf` to remain unchanged.
""".format
def main(args: list[str]) -> None:
raise SystemExit('This must be run as kitten themes')
if __name__ == '__main__':
main(sys.argv)
elif __name__ == '__doc__':
cd = sys.cli_docs # type: ignore
cd['usage'] = usage
cd['options'] = OPTIONS
cd['help_text'] = help_text
cd['short_desc'] = 'Manage kitty color schemes easily'
cd['args_completion'] = CompletionSpec.from_string('type:special group:complete_themes')
elif __name__ == '__conf__':
sys.options_definition = definition # type: ignore
+660
View File
@@ -0,0 +1,660 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package themes
import (
"fmt"
"github.com/kovidgoyal/kitty"
"io"
"maps"
"regexp"
"slices"
"strings"
"time"
"github.com/kovidgoyal/kitty/tools/config"
"github.com/kovidgoyal/kitty/tools/themes"
"github.com/kovidgoyal/kitty/tools/tui/loop"
"github.com/kovidgoyal/kitty/tools/tui/readline"
"github.com/kovidgoyal/kitty/tools/utils"
"github.com/kovidgoyal/kitty/tools/wcswidth"
)
var _ = fmt.Print
type State int
const (
FETCHING State = iota
BROWSING
SEARCHING
ACCEPTING
)
const SEPARATOR = "║"
type CachedData struct {
Recent []string `json:"recent"`
Category string `json:"category"`
}
type fetch_data struct {
themes *themes.Themes
err error
closer io.Closer
}
var category_filters = map[string]func(*themes.Theme) bool{
"all": func(*themes.Theme) bool { return true },
"dark": func(t *themes.Theme) bool { return t.IsDark() },
"light": func(t *themes.Theme) bool { return !t.IsDark() },
"user": func(t *themes.Theme) bool { return t.IsUserDefined() },
}
func recent_filter(items []string) func(*themes.Theme) bool {
allowed := utils.NewSetWithItems(items...)
return func(t *themes.Theme) bool {
return allowed.Has(t.Name())
}
}
type handler struct {
lp *loop.Loop
opts *Options
cached_data *CachedData
state State
fetch_result chan fetch_data
all_themes *themes.Themes
themes_closer io.Closer
themes_list *ThemesList
category_filters map[string]func(*themes.Theme) bool
colors_set_once bool
tabs []string
rl *readline.Readline
shortcut_tracker config.ShortcutTracker
keyboard_shortcuts []*config.KeyAction
}
// fetching {{{
func (self *handler) fetch_themes() {
r := fetch_data{}
r.themes, r.closer, r.err = themes.LoadThemes(time.Duration(self.opts.CacheAge * float64(time.Hour*24)))
self.lp.WakeupMainThread()
self.fetch_result <- r
}
func (self *handler) on_fetching_key_event(ev *loop.KeyEvent) error {
if ev.MatchesPressOrRepeat("esc") {
self.lp.Quit(0)
ev.Handled = true
}
return nil
}
func (self *handler) on_wakeup() error {
r := <-self.fetch_result
if r.err != nil {
return r.err
}
self.state = BROWSING
self.all_themes = r.themes
self.themes_closer = r.closer
self.redraw_after_category_change()
return nil
}
func (self *handler) draw_fetching_screen() {
self.lp.Println("Downloading themes from repository, please wait...")
}
// }}}
func (self *handler) finalize() {
t := self.themes_closer
if t != nil {
t.Close()
self.themes_closer = nil
}
}
func (self *handler) initialize() {
self.tabs = strings.Split("all dark light recent user", " ")
self.rl = readline.New(self.lp, readline.RlInit{DontMarkPrompts: true, Prompt: "/"})
self.themes_list = &ThemesList{}
self.fetch_result = make(chan fetch_data)
self.category_filters = make(map[string]func(*themes.Theme) bool, len(category_filters)+1)
maps.Copy(self.category_filters, category_filters)
self.category_filters["recent"] = recent_filter(self.cached_data.Recent)
self.keyboard_shortcuts = config.ResolveShortcuts(NewConfig().KeyboardShortcuts)
go self.fetch_themes()
self.draw_screen()
}
func (self *handler) enforce_cursor_state() {
self.lp.SetCursorVisible(self.state == FETCHING)
}
func (self *handler) draw_screen() {
self.lp.StartAtomicUpdate()
defer self.lp.EndAtomicUpdate()
self.lp.ClearScreen()
self.enforce_cursor_state()
switch self.state {
case FETCHING:
self.draw_fetching_screen()
case BROWSING, SEARCHING:
self.draw_browsing_screen()
case ACCEPTING:
self.draw_accepting_screen()
}
}
func (self *handler) current_category() string {
ans := self.cached_data.Category
if self.category_filters[ans] == nil {
ans = "all"
}
return ans
}
func (self *handler) set_current_category(category string) {
if self.category_filters[category] == nil {
category = "all"
}
self.cached_data.Category = category
}
func ReadKittyColorSettings() map[string]string {
settings := make(map[string]string, 512)
handle_line := func(key, val string) error {
if themes.AllColorSettingNames[key] {
settings[key] = val
}
return nil
}
config.ReadKittyConfig(handle_line)
return settings
}
func (self *handler) set_colors_to_current_theme() bool {
if self.themes_list == nil && self.colors_set_once {
return false
}
self.colors_set_once = true
if self.themes_list != nil {
t := self.themes_list.CurrentTheme()
if t != nil {
raw, err := t.AsEscapeCodes()
if err == nil {
self.lp.QueueWriteString(raw)
return true
}
}
}
self.lp.QueueWriteString(themes.ColorSettingsAsEscapeCodes(ReadKittyColorSettings()))
return true
}
func (self *handler) redraw_after_category_change() {
self.themes_list.UpdateThemes(self.all_themes.Filtered(self.category_filters[self.current_category()]))
self.set_colors_to_current_theme()
self.draw_screen()
}
func (self *handler) on_key_event(ev *loop.KeyEvent) error {
switch self.state {
case FETCHING:
return self.on_fetching_key_event(ev)
case BROWSING:
return self.on_browsing_key_event(ev)
case SEARCHING:
return self.on_searching_key_event(ev)
case ACCEPTING:
return self.on_accepting_key_event(ev)
}
return nil
}
// browsing ... {{{
func (self *handler) next_category(delta int) {
idx := slices.Index(self.tabs, self.current_category()) + delta + len(self.tabs)
self.set_current_category(self.tabs[idx%len(self.tabs)])
self.redraw_after_category_change()
}
func (self *handler) next(delta int, allow_wrapping bool) {
if self.themes_list.Next(delta, allow_wrapping) {
self.set_colors_to_current_theme()
self.draw_screen()
} else {
self.lp.Beep()
}
}
func (self *handler) on_browsing_key_event(ev *loop.KeyEvent) error {
if ev.MatchesPressOrRepeat("esc") {
self.lp.Quit(0)
ev.Handled = true
return nil
}
for _, cat := range self.tabs {
if ev.MatchesPressOrRepeat(cat[0:1]) || ev.MatchesPressOrRepeat("alt+"+cat[0:1]) || ev.MatchesCaseInsensitiveTextOrKey(cat[0:1]) {
ev.Handled = true
if cat != self.current_category() {
self.set_current_category(cat)
self.redraw_after_category_change()
return nil
}
}
}
if ev.MatchesPressOrRepeat("left") || ev.MatchesPressOrRepeat("shift+tab") {
self.next_category(-1)
ev.Handled = true
return nil
}
if ev.MatchesPressOrRepeat("right") || ev.MatchesPressOrRepeat("tab") {
self.next_category(1)
ev.Handled = true
return nil
}
if ev.MatchesPressOrRepeat("down") {
self.next(1, true)
ev.Handled = true
return nil
}
if ev.MatchesPressOrRepeat("up") {
self.next(-1, true)
ev.Handled = true
return nil
}
if ev.MatchesPressOrRepeat("page_down") {
ev.Handled = true
sz, err := self.lp.ScreenSize()
if err == nil {
self.next(int(sz.HeightCells)-3, false)
}
return nil
}
if ev.MatchesPressOrRepeat("page_up") {
ev.Handled = true
sz, err := self.lp.ScreenSize()
if err == nil {
self.next(3-int(sz.HeightCells), false)
}
return nil
}
if ev.MatchesCaseInsensitiveTextOrKey("/") {
ev.Handled = true
self.start_search()
return nil
}
if ev.MatchesPressOrRepeat("enter") {
ev.Handled = true
if self.themes_list == nil || self.themes_list.Len() == 0 {
self.lp.Beep()
} else {
self.state = ACCEPTING
self.draw_screen()
}
return nil
}
if ac := self.shortcut_tracker.Match(ev, self.keyboard_shortcuts); ac != nil {
switch ac.Name {
case "quit":
self.lp.Quit(0)
case "scroll_down":
self.next(1, true)
case "scroll_up":
self.next(-1, true)
case "search":
self.start_search()
case "accept":
if self.themes_list == nil || self.themes_list.Len() == 0 {
self.lp.Beep()
} else {
self.state = ACCEPTING
self.draw_screen()
}
}
return nil
}
return nil
}
func (self *handler) start_search() {
self.state = SEARCHING
self.rl.SetText(self.themes_list.current_search)
self.draw_screen()
}
func (self *handler) draw_browsing_screen() {
self.draw_tab_bar()
sz, err := self.lp.ScreenSize()
if err != nil {
return
}
num_rows := int(sz.HeightCells) - 2
mw := self.themes_list.max_width + 1
green_fg, _, _ := strings.Cut(self.lp.SprintStyled("fg=green", "|"), "|")
for _, l := range self.themes_list.Lines(num_rows) {
line := l.text
if l.is_current {
line = strings.ReplaceAll(line, themes.MARK_AFTER, green_fg)
self.lp.PrintStyled("fg=green", ">")
self.lp.PrintStyled("fg=green bold", line)
} else {
self.lp.PrintStyled("fg=green", " ")
self.lp.QueueWriteString(line)
}
self.lp.MoveCursorHorizontally(mw - l.width)
self.lp.Println(SEPARATOR)
num_rows--
}
for ; num_rows > 0; num_rows-- {
self.lp.MoveCursorHorizontally(mw + 1)
self.lp.Println(SEPARATOR)
}
if self.themes_list != nil && self.themes_list.Len() > 0 {
self.draw_theme_demo()
}
if self.state == BROWSING {
self.draw_bottom_bar()
} else {
self.draw_search_bar()
}
}
func (self *handler) draw_bottom_bar() {
sz, err := self.lp.ScreenSize()
if err != nil {
return
}
self.lp.MoveCursorTo(1, int(sz.HeightCells))
self.lp.PrintStyled("reverse", strings.Repeat(" ", int(sz.WidthCells)))
self.lp.QueueWriteString("\r")
draw_tab := func(t, sc string) {
text := self.mark_shortcut(utils.Capitalize(t), sc)
self.lp.PrintStyled("reverse", " "+text+" ")
}
draw_tab("search (/)", "s")
draw_tab("accept (⏎)", "c")
self.lp.QueueWriteString("\x1b[m")
}
func (self *handler) draw_search_bar() {
sz, err := self.lp.ScreenSize()
if err != nil {
return
}
self.lp.MoveCursorTo(1, int(sz.HeightCells))
self.lp.ClearToEndOfLine()
self.rl.RedrawNonAtomic()
}
func (self *handler) mark_shortcut(text, acc string) string {
acc_idx := strings.Index(strings.ToLower(text), strings.ToLower(acc))
return text[:acc_idx] + self.lp.SprintStyled("underline bold", text[acc_idx:acc_idx+1]) + text[acc_idx+1:]
}
func (self *handler) draw_tab_bar() {
sz, err := self.lp.ScreenSize()
if err != nil {
return
}
self.lp.PrintStyled("reverse", strings.Repeat(` `, int(sz.WidthCells)))
self.lp.QueueWriteString("\r")
cc := self.current_category()
draw_tab := func(text, name, acc string) {
is_active := name == cc
if is_active {
text := self.lp.SprintStyled("italic", fmt.Sprintf("%s #%d", text, self.themes_list.Len()))
self.lp.Printf(" %s ", text)
} else {
text = self.mark_shortcut(text, acc)
self.lp.PrintStyled("reverse", " "+text+" ")
}
}
for _, title := range self.tabs {
draw_tab(utils.Capitalize(title), title, string([]rune(title)[0]))
}
self.lp.Println("\x1b[m")
}
func center_string(x string, width int) string {
l := wcswidth.Stringwidth(x)
spaces := int(float64(width-l) / 2)
return strings.Repeat(" ", utils.Max(0, spaces)) + x + strings.Repeat(" ", utils.Max(0, width-(spaces+l)))
}
func (self *handler) draw_theme_demo() {
ssz, err := self.lp.ScreenSize()
if err != nil {
return
}
theme := self.themes_list.CurrentTheme()
if theme == nil {
return
}
xstart := self.themes_list.max_width + 3
sz := int(ssz.WidthCells) - xstart
if sz < 20 {
return
}
sz--
y := 0
colors := strings.Split(`black red green yellow blue magenta cyan white`, ` `)
trunc := sz/8 - 1
pat := regexp.MustCompile(`\s+`)
next_line := func() {
self.lp.QueueWriteString("\r")
y++
self.lp.MoveCursorTo(xstart, y+1)
self.lp.QueueWriteString(SEPARATOR + " ")
}
write_para := func(text string) {
text = pat.ReplaceAllLiteralString(text, " ")
for text != "" {
t, sp := wcswidth.TruncateToVisualLengthWithWidth(text, sz)
self.lp.QueueWriteString(t)
next_line()
text = text[sp:]
}
}
write_colors := func(bg string) {
for _, intense := range []bool{false, true} {
buf := strings.Builder{}
buf.Grow(1024)
for _, c := range colors {
s := c
if intense {
s = "bright-" + s
}
sTrunc := s
if len(sTrunc) > trunc {
sTrunc = sTrunc[:trunc]
}
buf.WriteString(self.lp.SprintStyled("fg="+s, sTrunc))
buf.WriteString(" ")
}
text := strings.TrimSpace(buf.String())
if bg == "" {
self.lp.QueueWriteString(text)
} else {
s := bg
if intense {
s = "bright-" + s
}
self.lp.PrintStyled("bg="+s, text)
}
next_line()
}
next_line()
}
self.lp.MoveCursorTo(1, 1)
next_line()
self.lp.PrintStyled("fg=green bold", center_string(theme.Name(), sz))
next_line()
if theme.Author() != "" {
self.lp.PrintStyled("italic", center_string(theme.Author(), sz))
next_line()
}
if theme.Blurb() != "" {
next_line()
write_para(theme.Blurb())
next_line()
}
write_colors("")
for _, bg := range colors {
write_colors(bg)
}
}
// }}}
// accepting {{{
func (self *handler) on_accepting_key_event(ev *loop.KeyEvent) error {
if ev.MatchesPressOrRepeat("esc") {
ev.Handled = true
self.lp.Quit(0)
return nil
}
if ac := self.shortcut_tracker.Match(ev, self.keyboard_shortcuts); ac != nil {
switch ac.Name {
case "quit":
self.lp.Quit(0)
case "abort":
self.state = BROWSING
self.draw_screen()
case "place_theme":
self.themes_list.CurrentTheme().SaveInDir(utils.ConfigDir())
self.update_recent()
self.lp.Quit(0)
case "modify_conf":
self.themes_list.CurrentTheme().SaveInConf(utils.ConfigDir(), self.opts.ReloadIn, self.opts.ConfigFileName)
self.update_recent()
self.lp.Quit(0)
case "dark_scheme":
self.themes_list.CurrentTheme().SaveInFile(utils.ConfigDir(), kitty.DarkThemeFileName)
self.update_recent()
self.lp.Quit(0)
case "light_scheme":
self.themes_list.CurrentTheme().SaveInFile(utils.ConfigDir(), kitty.LightThemeFileName)
self.update_recent()
self.lp.Quit(0)
case "no_preference":
self.themes_list.CurrentTheme().SaveInFile(utils.ConfigDir(), kitty.NoPreferenceThemeFileName)
self.update_recent()
self.lp.Quit(0)
}
return nil
}
return nil
}
func (self *handler) update_recent() {
if self.themes_list != nil {
recent := slices.Clone(self.cached_data.Recent)
name := self.themes_list.CurrentTheme().Name()
recent = utils.Remove(recent, name)
recent = append([]string{name}, recent...)
if len(recent) > 20 {
recent = recent[:20]
}
self.cached_data.Recent = recent
}
}
func (self *handler) draw_accepting_screen() {
name := self.themes_list.CurrentTheme().Name()
name = self.lp.SprintStyled("fg=green bold", name)
kc := self.lp.SprintStyled("italic", self.opts.ConfigFileName)
ac := func(x string) string {
return self.lp.SprintStyled("fg=red underline=true", x)
}
self.lp.AllowLineWrapping(true)
defer self.lp.AllowLineWrapping(false)
self.lp.Printf(`You have chosen the %s theme`, name)
self.lp.Println()
self.lp.Println()
self.lp.Println(`What would you like to do?`)
self.lp.Println()
self.lp.Printf(` %sodify %s to load %s`, ac("M"), kc, name)
self.lp.Println()
self.lp.Println()
self.lp.Printf(` %slace the theme file in %s but do not modify %s`, ac("P"), utils.ConfigDir(), kc)
self.lp.Println()
self.lp.Println()
self.lp.Printf(` Save as colors to use when the OS switches to:`)
self.lp.Println()
self.lp.Printf(` %sark mode`, ac("D"))
self.lp.Println()
self.lp.Printf(` %sight mode`, ac("L"))
self.lp.Println()
self.lp.Printf(` %so preference mode`, ac("N"))
self.lp.Println()
self.lp.Println()
self.lp.Printf(` %sbort and return to list of themes`, ac("A"))
self.lp.Println()
self.lp.Println()
self.lp.Printf(` %suit`, ac("Q"))
self.lp.Println()
}
// }}}
// searching {{{
func (self *handler) update_search() {
text := self.rl.AllText()
if self.themes_list.UpdateSearch(text) {
self.set_colors_to_current_theme()
self.draw_screen()
} else {
self.draw_search_bar()
}
}
func (self *handler) on_text(text string, a, b bool) error {
if self.state == SEARCHING {
err := self.rl.OnText(text, a, b)
if err != nil {
return err
}
self.update_search()
}
return nil
}
func (self *handler) on_searching_key_event(ev *loop.KeyEvent) error {
if ev.MatchesPressOrRepeat("enter") {
ev.Handled = true
self.state = BROWSING
self.draw_bottom_bar()
return nil
}
if ev.MatchesPressOrRepeat("esc") {
ev.Handled = true
self.state = BROWSING
self.themes_list.UpdateSearch("")
self.set_colors_to_current_theme()
self.draw_screen()
return nil
}
err := self.rl.OnKeyEvent(ev)
if err != nil {
return err
}
if ev.Handled {
self.update_search()
}
return nil
}
// }}}