Clean up reader_write_title to work with wcstring

This commit is contained in:
ridiculousfish 2014-08-02 21:01:40 -07:00
parent 87abcecca6
commit b97a94ccc8
3 changed files with 15 additions and 18 deletions

View File

@ -3251,7 +3251,7 @@ static int builtin_fg(parser_t &parser, wchar_t **argv)
const wcstring ft = tok_first(j->command_wcstr()); const wcstring ft = tok_first(j->command_wcstr());
if (! ft.empty()) if (! ft.empty())
env_set(L"_", ft.c_str(), ENV_EXPORT); env_set(L"_", ft.c_str(), ENV_EXPORT);
reader_write_title(j->command_wcstr()); reader_write_title(j->command());
make_first(j); make_first(j);
job_set_flag(j, JOB_FOREGROUND, 1); job_set_flag(j, JOB_FOREGROUND, 1);

View File

@ -902,9 +902,8 @@ bool reader_thread_job_is_stale()
return (void*)(uintptr_t) s_generation_count != pthread_getspecific(generation_count_key); return (void*)(uintptr_t) s_generation_count != pthread_getspecific(generation_count_key);
} }
void reader_write_title(const wchar_t *cmd) void reader_write_title(const wcstring &cmd)
{ {
const wchar_t *title;
const env_var_t term_str = env_get_string(L"TERM"); const env_var_t term_str = env_get_string(L"TERM");
/* /*
@ -934,7 +933,6 @@ void reader_write_title(const wchar_t *cmd)
{ {
char *n = ttyname(STDIN_FILENO); char *n = ttyname(STDIN_FILENO);
if (contains(term, L"linux")) if (contains(term, L"linux"))
{ {
return; return;
@ -942,24 +940,23 @@ void reader_write_title(const wchar_t *cmd)
if (strstr(n, "tty") || strstr(n, "/vc/")) if (strstr(n, "tty") || strstr(n, "/vc/"))
return; return;
} }
wcstring fish_title = L"fish_title"; wcstring fish_title_command = DEFAULT_TITLE;
if (cmd) { if (function_exists(L"fish_title"))
fish_title.append(L" "); {
fish_title.append(parse_util_escape_string_with_quote(cmd, L'\0')); fish_title_command = L"fish_title";
if (! cmd.empty())
{
fish_title_command.append(L" ");
fish_title_command.append(parse_util_escape_string_with_quote(cmd, L'\0'));
}
} }
title = function_exists(L"fish_title")?fish_title.c_str():DEFAULT_TITLE;
if (wcslen(title) ==0)
return;
wcstring_list_t lst; wcstring_list_t lst;
proc_push_interactive(0); proc_push_interactive(0);
if (exec_subshell(title, lst, false /* do not apply exit status */) != -1) if (exec_subshell(fish_title_command, lst, false /* do not apply exit status */) != -1)
{ {
if (! lst.empty()) if (! lst.empty())
{ {
@ -1020,7 +1017,7 @@ static void exec_prompt()
} }
/* Write the screen title */ /* Write the screen title */
reader_write_title(0); reader_write_title(L"");
} }
void reader_init() void reader_init()
@ -2540,7 +2537,7 @@ void reader_run_command(parser_t &parser, const wcstring &cmd)
if (! ft.empty()) if (! ft.empty())
env_set(L"_", ft.c_str(), ENV_GLOBAL); env_set(L"_", ft.c_str(), ENV_GLOBAL);
reader_write_title(cmd.c_str()); reader_write_title(cmd);
term_donate(); term_donate();

View File

@ -119,7 +119,7 @@ void reader_pop_current_filename();
\param cmd Command line string passed to \c fish_title if is defined. \param cmd Command line string passed to \c fish_title if is defined.
*/ */
void reader_write_title(const wchar_t *cmd); void reader_write_title(const wcstring &cmd);
/** /**
Call this function to tell the reader that a repaint is needed, and Call this function to tell the reader that a repaint is needed, and