From 5d86f5c93f00fd9167626ed24d9003d33bb576a2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 14 May 2024 20:03:06 +0530 Subject: [PATCH] Start work on face panel --- kittens/choose_fonts/face.go | 58 +++++++++++++++++++++++++++++++++++ kittens/choose_fonts/faces.go | 16 ++++++++++ kittens/choose_fonts/ui.go | 7 +++-- 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 kittens/choose_fonts/face.go diff --git a/kittens/choose_fonts/face.go b/kittens/choose_fonts/face.go new file mode 100644 index 000000000..f6bde91a4 --- /dev/null +++ b/kittens/choose_fonts/face.go @@ -0,0 +1,58 @@ +package choose_fonts + +import ( + "fmt" + "kitty/tools/tui/loop" + "sync" +) + +var _ = fmt.Print + +type face_panel struct { + handler *handler + + family, which string + settings faces_settings + setting string + preview_cache map[faces_preview_key]map[string]RenderedSampleTransmit + preview_cache_mutex sync.Mutex +} + +func (self *face_panel) draw_screen() (err error) { + return +} + +func (self *face_panel) initialize(h *handler) (err error) { + self.handler = h + self.preview_cache = make(map[faces_preview_key]map[string]RenderedSampleTransmit) + return +} + +func (self *face_panel) on_wakeup() error { + return self.handler.draw_screen() +} + +func (self *face_panel) on_click(id string) (err error) { + return +} + +func (self *face_panel) on_key_event(event *loop.KeyEvent) (err error) { + if event.MatchesPressOrRepeat("esc") { + event.Handled = true + self.handler.current_pane = &self.handler.faces + return self.handler.draw_screen() + } + return +} + +func (self *face_panel) on_text(text string, from_key_event bool, in_bracketed_paste bool) (err error) { + return +} + +func (self *face_panel) on_enter(family, which string, settings faces_settings) error { + self.family = family + self.settings = settings + self.which = which + self.handler.current_pane = self + return self.handler.draw_screen() +} diff --git a/kittens/choose_fonts/faces.go b/kittens/choose_fonts/faces.go index b70c4da0e..40905e34a 100644 --- a/kittens/choose_fonts/faces.go +++ b/kittens/choose_fonts/faces.go @@ -117,6 +117,22 @@ func (self *faces) on_key_event(event *loop.KeyEvent) (err error) { } func (self *faces) on_text(text string, from_key_event bool, in_bracketed_paste bool) (err error) { + if from_key_event { + which := "" + switch text { + case "r", "R": + which = "font_family" + case "b", "B": + which = "bold_font" + case "i", "I": + which = "italic_font" + case "o", "O": + which = "bold_italic_font" + } + if which != "" { + return self.handler.face_pane.on_enter(self.family, which, self.settings) + } + } return } diff --git a/kittens/choose_fonts/ui.go b/kittens/choose_fonts/ui.go index ba86fa8b0..5014f1b6f 100644 --- a/kittens/choose_fonts/ui.go +++ b/kittens/choose_fonts/ui.go @@ -51,8 +51,9 @@ type handler struct { graphics_manager graphics_manager temp_dir string - listing FontList - faces faces + listing FontList + faces faces + face_pane face_panel panes []pane current_pane pane @@ -75,7 +76,7 @@ func (h *handler) initialize() (err error) { h.lp.SetCursorVisible(false) h.lp.OnQueryResponse = h.on_query_response h.lp.QueryTerminal("font_size", "dpi_x", "dpi_y", "foreground", "background") - h.panes = []pane{&h.listing, &h.faces} + h.panes = []pane{&h.listing, &h.faces, &h.face_pane} for _, pane := range h.panes { if err = pane.initialize(h); err != nil { return err