|
| 1 | +*tpipeline-kitty.txt* Kitty integration |
| 2 | +*tpipeline-kitty* |
| 3 | + |
| 4 | + |
| 5 | +Introduction |tpipeline-kitty-introduction| |
| 6 | +Configuration |tpipeline-kitty-configure| |
| 7 | + |
| 8 | +============================================================================== |
| 9 | +INTRODUCTION *tpipeline-kitty-introduction* |
| 10 | + |
| 11 | +It is possible to embed the vim statusline in the statusline of the kitty |
| 12 | +terminal emulator, instead of embedding it in the tmux statusline. |
| 13 | +This can be achieved by utilizing the |g:tpipeline_refreshcmd| command and by |
| 14 | +adapting the kitty config. |
| 15 | + |
| 16 | +------------------------------------------------------------------------------ |
| 17 | +CONFIGURATION *tpipeline-kitty-configure* |
| 18 | + |
| 19 | +From this plugin side you need to setup |g:tpipeline_refreshcmd| such that it |
| 20 | +notifies kitty everytime the vim statusline changes. Hence you may put |
| 21 | +something like the following in your vim config: |
| 22 | + |
| 23 | +> |
| 24 | + let g:tpipeline_refreshcmd = "kitty @ set-tab-title Master test" |
| 25 | +< |
| 26 | + |
| 27 | +Then to actually receive the interrupts on every update at kitty's side, make |
| 28 | +sure your `kitty.conf` contains the following lines: |
| 29 | + |
| 30 | +> |
| 31 | + allow_remote_control yes |
| 32 | + listen_on unix:@mykitty |
| 33 | + tab_bar_style custom |
| 34 | + tab_bar_min_tabs 1 |
| 35 | + tab_separator "" |
| 36 | +< |
| 37 | + |
| 38 | +Then the final thing left to do is to write a short Python wrapper script that |
| 39 | +handles the statusline updates. The following python script should be copied |
| 40 | +to `~/.config/kitty/tab_bar.py`: |
| 41 | + |
| 42 | +> |
| 43 | +import os |
| 44 | +from kitty.boss import get_boss |
| 45 | +from kitty.fast_data_types import Screen, add_timer |
| 46 | +from kitty.tab_bar import DrawData, ExtraData, TabBarData, draw_title, as_rgb |
| 47 | +from kitty.utils import color_as_int |
| 48 | + |
| 49 | +timer_id = None |
| 50 | + |
| 51 | +def parse_stl(screen: Screen, draw_data: DrawData, stl: str, draw: bool): |
| 52 | + pos = 0 |
| 53 | + length = 0 |
| 54 | + while pos < len(stl): |
| 55 | + next = stl.find("#[", pos) |
| 56 | + if next == -1: |
| 57 | + length += len(stl[pos:]) |
| 58 | + if draw: |
| 59 | + screen.draw(stl[pos:]) |
| 60 | + return length |
| 61 | + |
| 62 | + length += len(stl[pos:next]) |
| 63 | + if draw: |
| 64 | + screen.draw(stl[pos:next]) |
| 65 | + pos = next + 1 |
| 66 | + next = stl.find("]", pos) |
| 67 | + if next == -1: |
| 68 | + length += len(stl[pos:]) |
| 69 | + if draw: |
| 70 | + screen.draw(stl[pos:]) |
| 71 | + return length |
| 72 | + |
| 73 | + fmt = stl[pos+1:next].split(",") |
| 74 | + for f in fmt: |
| 75 | + if f.startswith("fg="): |
| 76 | + if f == "fg=default": |
| 77 | + screen.cursor.fg = as_rgb(int(draw_data.default_fg)) |
| 78 | + else: |
| 79 | + screen.cursor.fg = as_rgb(int(f[4:10], 16)) |
| 80 | + elif f.startswith("bg="): |
| 81 | + if f == "bg=default": |
| 82 | + screen.cursor.bg = as_rgb(int(draw_data.default_bg)) |
| 83 | + else: |
| 84 | + screen.cursor.bg = as_rgb(int(f[4:10], 16)) |
| 85 | + |
| 86 | + pos = next + 1 |
| 87 | + |
| 88 | + return length |
| 89 | + |
| 90 | +def draw_tpipeline(screen: Screen, draw_data: DrawData): |
| 91 | + stl = open('/tmp/tmux-' + str(os.getuid()) + '/default-$0-vimbridge').readline() |
| 92 | + parse_stl(screen, draw_data, stl, True) |
| 93 | + stl = open('/tmp/tmux-' + str(os.getuid()) + '/default-$0-vimbridge-R').readline() |
| 94 | + length = parse_stl(screen, draw_data, stl, False) |
| 95 | + screen.draw(" " * (screen.columns - screen.cursor.x - length)) |
| 96 | + length = parse_stl(screen, draw_data, stl, True) |
| 97 | + |
| 98 | +def redraw_tab_bar(timer_id): |
| 99 | + tm = get_boss().active_tab_manager |
| 100 | + if tm is not None: |
| 101 | + tm.mark_tab_bar_dirty() |
| 102 | + |
| 103 | +def draw_tab( |
| 104 | + draw_data: DrawData, screen: Screen, tab: TabBarData, |
| 105 | + before: int, max_title_length: int, index: int, is_last: bool, |
| 106 | + extra_data: ExtraData |
| 107 | + ) -> int: |
| 108 | + |
| 109 | + global timer_id |
| 110 | + if timer_id is None: |
| 111 | + timer_id = add_timer(redraw_tab_bar, 0.3, True) |
| 112 | + |
| 113 | + if index == 1: |
| 114 | + draw_tpipeline(screen, draw_data) |
| 115 | + |
| 116 | + return screen.cursor.x |
| 117 | +< |
| 118 | + |
| 119 | +That's it! Make sure to restart kitty after these changes. Now the vim |
| 120 | +statusline should be embedded in the kitty statusline instead of the tmux |
| 121 | +statusline. |
| 122 | + |
| 123 | +============================================================================== |
| 124 | + vim:tw=78:sw=4:ts=8:ft=help:norl:noet: |
0 commit comments