mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 09:15:57 +02:00
More work on choose_fonts
This commit is contained in:
@@ -29,6 +29,8 @@ type faces struct {
|
||||
preview_cache_mutex sync.Mutex
|
||||
}
|
||||
|
||||
const highlight_key_style = "fg=magenta bold"
|
||||
|
||||
func (self *faces) draw_screen() (err error) {
|
||||
lp := self.handler.lp
|
||||
lp.SetCursorVisible(false)
|
||||
@@ -36,7 +38,7 @@ func (self *faces) draw_screen() (err error) {
|
||||
styled := lp.SprintStyled
|
||||
lp.QueueWriteString(self.handler.format_title(self.family, 0))
|
||||
lines := []string{
|
||||
fmt.Sprintf("Press %s to select this font, %s to go back to the font list or any of the %s keys below to fine-tune the appearance of the individual font styles.", styled("fg=green", "Enter"), styled("fg=red", "Esc"), styled("fg=magenta bold", "highlighted")), "",
|
||||
fmt.Sprintf("Press %s to select this font, %s to go back to the font list or any of the %s keys below to fine-tune the appearance of the individual font styles.", styled("fg=green", "Enter"), styled("fg=red", "Esc"), styled(highlight_key_style, "highlighted")), "",
|
||||
}
|
||||
_, y, str := self.handler.render_lines.InRectangle(lines, 0, 2, int(sz.WidthCells), int(sz.HeightCells), &self.handler.mouse_state, self.on_click)
|
||||
|
||||
@@ -85,10 +87,10 @@ func (self *faces) draw_screen() (err error) {
|
||||
y += num_lines + 1
|
||||
}
|
||||
}
|
||||
d(`font_family`, styled("fg=magenta bold", "R")+`egular`)
|
||||
d(`bold_font`, styled("fg=magenta bold", "B")+`old`)
|
||||
d(`italic_font`, styled("fg=magenta bold", "I")+`talic`)
|
||||
d(`bold_italic_font`, "B"+styled("fg=magenta bold", "o")+`ld-Italic`)
|
||||
d(`font_family`, styled(highlight_key_style, "R")+`egular`)
|
||||
d(`bold_font`, styled(highlight_key_style, "B")+`old`)
|
||||
d(`italic_font`, styled(highlight_key_style, "I")+`talic`)
|
||||
d(`bold_italic_font`, "B"+styled(highlight_key_style, "o")+`ld-Italic`)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -113,6 +115,10 @@ func (self *faces) on_key_event(event *loop.KeyEvent) (err error) {
|
||||
self.handler.current_pane = &self.handler.listing
|
||||
return self.handler.draw_screen()
|
||||
}
|
||||
if event.MatchesPressOrRepeat("enter") {
|
||||
event.Handled = true
|
||||
return self.handler.final_pane.on_enter(self.family, self.settings)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
95
kittens/choose_fonts/final.go
Normal file
95
kittens/choose_fonts/final.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package choose_fonts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"kitty/tools/tui/loop"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
type final_pane struct {
|
||||
handler *handler
|
||||
settings faces_settings
|
||||
family string
|
||||
lp *loop.Loop
|
||||
}
|
||||
|
||||
func (self *final_pane) render_lines(start_y int, lines ...string) (y int) {
|
||||
sz, _ := self.handler.lp.ScreenSize()
|
||||
_, y, str := self.handler.render_lines.InRectangle(lines, 0, start_y, int(sz.WidthCells), int(sz.HeightCells)-y, &self.handler.mouse_state, self.on_click)
|
||||
self.handler.lp.QueueWriteString(str)
|
||||
return
|
||||
}
|
||||
|
||||
func (self *final_pane) draw_screen() (err error) {
|
||||
s := self.lp.SprintStyled
|
||||
h := func(x string) string { return s(highlight_key_style, x) }
|
||||
|
||||
self.render_lines(0,
|
||||
fmt.Sprintf("You have chosen the %s family", s(current_val_style, self.family)),
|
||||
"",
|
||||
"What would you like to do?",
|
||||
"",
|
||||
fmt.Sprintf("%s to modify %s and use the new fonts", h("Enter"), s("italic", `kitty.conf`)),
|
||||
"",
|
||||
fmt.Sprintf("%s to abort and return to font selection", h("Esc")),
|
||||
"",
|
||||
fmt.Sprintf("%s to write the new font settings to %s", h("s"), s("italic", `STDOUT`)),
|
||||
"",
|
||||
fmt.Sprintf("%s to quit", h("Ctrl+c")),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
func (self *final_pane) initialize(h *handler) (err error) {
|
||||
self.handler = h
|
||||
self.lp = h.lp
|
||||
return
|
||||
}
|
||||
|
||||
func (self *final_pane) on_wakeup() error {
|
||||
return self.handler.draw_screen()
|
||||
}
|
||||
|
||||
func (self *final_pane) on_click(id string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (self faces_settings) serialized() string {
|
||||
return strings.Join([]string{
|
||||
"font_family " + self.font_family,
|
||||
"bold_font " + self.bold_font,
|
||||
"italic_font " + self.italic_font,
|
||||
"bold_italic_font " + self.bold_italic_font,
|
||||
}, "\n")
|
||||
}
|
||||
|
||||
func (self *final_pane) 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 *final_pane) on_text(text string, from_key_event bool, in_bracketed_paste bool) (err error) {
|
||||
if from_key_event {
|
||||
switch text {
|
||||
case "s", "S":
|
||||
output_on_exit = self.settings.serialized() + "\n"
|
||||
self.lp.Quit(0)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (self *final_pane) on_enter(family string, settings faces_settings) error {
|
||||
self.settings = settings
|
||||
self.family = family
|
||||
self.handler.current_pane = self
|
||||
return self.handler.draw_screen()
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package choose_fonts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"kitty/tools/cli"
|
||||
"kitty/tools/tty"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
|
||||
var _ = fmt.Print
|
||||
var debugprintln = tty.DebugPrintln
|
||||
var output_on_exit string
|
||||
|
||||
func main() (rc int, err error) {
|
||||
if err = kitty_font_backend.start(); err != nil {
|
||||
@@ -59,6 +61,9 @@ func main() (rc int, err error) {
|
||||
lp.KillIfSignalled()
|
||||
return 1, nil
|
||||
}
|
||||
if output_on_exit != "" {
|
||||
os.Stdout.WriteString(output_on_exit)
|
||||
}
|
||||
return lp.ExitCode(), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -51,9 +51,10 @@ type handler struct {
|
||||
graphics_manager graphics_manager
|
||||
temp_dir string
|
||||
|
||||
listing FontList
|
||||
faces faces
|
||||
face_pane face_panel
|
||||
listing FontList
|
||||
faces faces
|
||||
face_pane face_panel
|
||||
final_pane final_pane
|
||||
|
||||
panes []pane
|
||||
current_pane pane
|
||||
@@ -76,7 +77,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.face_pane}
|
||||
h.panes = []pane{&h.listing, &h.faces, &h.face_pane, &h.final_pane}
|
||||
for _, pane := range h.panes {
|
||||
if err = pane.initialize(h); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user