Still have to do the fix for zsh/fish
This commit is contained in:
Kovid Goyal 2022-02-27 10:20:19 +05:30
parent f9621b1e11
commit d53f8f24c4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 36 additions and 6 deletions

View File

@ -406,6 +406,10 @@ dispatch_osc(Screen *screen, PyObject DUMP_UNUSED *dump_callback) {
START_DISPATCH
DISPATCH_OSC(set_title);
END_DISPATCH
case 22222:
START_DISPATCH
DISPATCH_OSC(set_title_base64);
END_DISPATCH
case 4:
case 104:
START_DISPATCH

View File

@ -1967,6 +1967,12 @@ set_title(Screen *self, PyObject *title) {
CALLBACK("title_changed", "O", title);
}
void
set_title_base64(Screen *self, PyObject *title) {
CALLBACK("title_changed", "OO", title, Py_True);
}
void
desktop_notify(Screen *self, unsigned int osc_code, PyObject *data) {
CALLBACK("desktop_notify", "IO", osc_code, data);

View File

@ -211,6 +211,7 @@ void screen_handle_print(Screen *, PyObject *cmd);
void screen_designate_charset(Screen *, uint32_t which, uint32_t as);
void screen_use_latin1(Screen *, bool);
void set_title(Screen *self, PyObject*);
void set_title_base64(Screen *self, PyObject*);
void desktop_notify(Screen *self, unsigned int, PyObject*);
void set_icon(Screen *self, PyObject*);
void set_dynamic_color(Screen *self, unsigned int code, PyObject*);

View File

@ -57,6 +57,16 @@ if TYPE_CHECKING:
from .file_transmission import FileTransmission
def process_title_from_child(title: str, is_base64: bool) -> str:
if is_base64:
from base64 import standard_b64decode
try:
title = standard_b64decode(title).decode('utf-8', 'replace')
except Exception:
title = 'undecodeable title'
return sanitize_title(title)
class WindowDict(TypedDict):
id: int
is_focused: bool
@ -734,8 +744,8 @@ class Window:
# Cancel IME composition after loses focus
update_ime_position_for_window(self.id, False, True)
def title_changed(self, new_title: Optional[str]) -> None:
self.child_title = sanitize_title(new_title or self.default_title)
def title_changed(self, new_title: Optional[str], is_base64: bool = False) -> None:
self.child_title = process_title_from_child(new_title or self.default_title, is_base64)
if self.override_title is None:
self.title_updated()

View File

@ -21,7 +21,7 @@ from kitty.options.parse import merge_result_dicts
from kitty.options.types import Options, defaults
from kitty.types import MouseEvent
from kitty.utils import read_screen_size
from kitty.window import process_remote_print
from kitty.window import process_remote_print, process_title_from_child
class Callbacks:
@ -32,8 +32,8 @@ class Callbacks:
def write(self, data) -> None:
self.wtcbuf += data
def title_changed(self, data) -> None:
self.titlebuf.append(data)
def title_changed(self, data, is_base64=False) -> None:
self.titlebuf.append(process_title_from_child(data, is_base64))
def icon_changed(self, data) -> None:
self.iconbuf += data

View File

@ -266,6 +266,14 @@ PS1="{ps1}"
pty.wait_till(lambda: pty.screen.cursor.shape == 0)
pty.write_to_child('\x04')
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM)
pty.write_to_child('\x04')
pty.send_cmd_to_child('clear')
pty.wait_till(lambda: pty.callbacks.titlebuf)
with self.run_shell(shell='bash', rc=f'''PS1="{ps1}"''') as pty:
pty.callbacks.clear()
pty.send_cmd_to_child('printf "%s\x16\a%s" "a" "b"')
pty.wait_till(lambda: 'ab' in pty.screen_contents())
self.ae(pty.screen_contents(), 'prompt> printf "%s^G%s" "a" "b"\nab')
for ps1 in ('line1\\nline\\2\\prompt> ', 'line1\nprompt> ', 'line1\\nprompt> ',):
with self.subTest(ps1=ps1), self.run_shell(

View File

@ -139,7 +139,8 @@ _ksi_main() {
last_cmd=$(HISTTIMEFORMAT= builtin history 1)
last_cmd="${last_cmd#*[[:digit:]]*[[:space:]]}" # remove leading history number
last_cmd="${last_cmd#"${last_cmd%%[![:space:]]*}"}" # remove remaining leading whitespace
builtin printf "\e]2;%s\a" "${last_cmd}"
last_cmd=$(printf "%s" "$last_cmd" | base64 | tr -d \\n)
builtin printf "\e]22222;%s\a" "${last_cmd}"
}
_ksi_prompt[ps0_suffix]+='$(_ksi_get_current_command)'
fi