main.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package choose_fonts
  2. import (
  3. "fmt"
  4. "os"
  5. "kitty/tools/cli"
  6. "kitty/tools/tty"
  7. "kitty/tools/tui/loop"
  8. )
  9. var _ = fmt.Print
  10. var debugprintln = tty.DebugPrintln
  11. var output_on_exit string
  12. func main(opts *Options) (rc int, err error) {
  13. if err = kitty_font_backend.start(); err != nil {
  14. return 1, err
  15. }
  16. defer func() {
  17. if werr := kitty_font_backend.release(); werr != nil {
  18. if err == nil {
  19. err = werr
  20. }
  21. if rc == 0 {
  22. rc = 1
  23. }
  24. }
  25. }()
  26. lp, err := loop.New()
  27. if err != nil {
  28. return 1, err
  29. }
  30. lp.MouseTrackingMode(loop.FULL_MOUSE_TRACKING)
  31. h := &handler{lp: lp, opts: opts}
  32. lp.OnInitialize = func() (string, error) {
  33. lp.AllowLineWrapping(false)
  34. lp.SetWindowTitle(`Choose a font for kitty`)
  35. return "", h.initialize()
  36. }
  37. lp.OnWakeup = h.on_wakeup
  38. lp.OnEscapeCode = h.on_escape_code
  39. lp.OnFinalize = func() string {
  40. h.finalize()
  41. lp.SetCursorVisible(true)
  42. return ``
  43. }
  44. lp.OnMouseEvent = h.on_mouse_event
  45. lp.OnResize = func(_, _ loop.ScreenSize) error {
  46. return h.draw_screen()
  47. }
  48. lp.OnKeyEvent = h.on_key_event
  49. lp.OnText = h.on_text
  50. err = lp.Run()
  51. if err != nil {
  52. return 1, err
  53. }
  54. ds := lp.DeathSignalName()
  55. if ds != "" {
  56. fmt.Println("Killed by signal: ", ds)
  57. lp.KillIfSignalled()
  58. return 1, nil
  59. }
  60. if output_on_exit != "" {
  61. os.Stdout.WriteString(output_on_exit)
  62. }
  63. return lp.ExitCode(), nil
  64. }
  65. type Options struct {
  66. Reload_in string
  67. }
  68. func EntryPoint(root *cli.Command) {
  69. ans := root.AddSubCommand(&cli.Command{
  70. Name: "choose-fonts",
  71. ShortDescription: "Choose the fonts used in kitty",
  72. Run: func(cmd *cli.Command, args []string) (rc int, err error) {
  73. opts := Options{}
  74. if err = cmd.GetOptionValues(&opts); err != nil {
  75. return 1, err
  76. }
  77. return main(&opts)
  78. },
  79. })
  80. ans.Add(cli.OptionSpec{
  81. Name: "--reload-in",
  82. Dest: "Reload_in",
  83. Type: "choices",
  84. Choices: "parent, all, none",
  85. Default: "parent",
  86. Help: `By default, this kitten will signal only the parent kitty instance it is
  87. running in to reload its config, after making changes. Use this option to
  88. instead either not reload the config at all or in all running kitty instances.`,
  89. })
  90. clone := root.AddClone(ans.Group, ans)
  91. clone.Hidden = false
  92. clone.Name = "choose_fonts"
  93. }