fix(fill): Add `terminal-width` argument to explicitly define terminal's width (#3090)
Add `terminal-width` argument to explicitly define terminal's width Update pwsh,bash,zsh,fish init scripts with `terminal-width` argument Co-authored-by: Kevin Song <chips@ksong.dev> Co-authored-by: Kevin Song <4605384+chipbuster@users.noreply.github.com>
This commit is contained in:
parent
3c995d3e3e
commit
6464693165
|
@ -131,6 +131,12 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
let right = arguments.is_present("right");
|
let right = arguments.is_present("right");
|
||||||
|
|
||||||
|
let width = arguments
|
||||||
|
.value_of("terminal_width")
|
||||||
|
.and_then(|w| w.parse().ok())
|
||||||
|
.or_else(|| terminal_size().map(|(w, _)| w.0 as usize))
|
||||||
|
.unwrap_or(80);
|
||||||
|
|
||||||
Context {
|
Context {
|
||||||
config,
|
config,
|
||||||
properties,
|
properties,
|
||||||
|
@ -141,9 +147,7 @@ impl<'a> Context<'a> {
|
||||||
repo: OnceCell::new(),
|
repo: OnceCell::new(),
|
||||||
shell,
|
shell,
|
||||||
right,
|
right,
|
||||||
width: terminal_size()
|
width,
|
||||||
.map(|(w, _)| w.0 as usize)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
env: HashMap::new(),
|
env: HashMap::new(),
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -49,10 +49,10 @@ starship_precmd() {
|
||||||
if [[ $STARSHIP_START_TIME ]]; then
|
if [[ $STARSHIP_START_TIME ]]; then
|
||||||
STARSHIP_END_TIME=$(::STARSHIP:: time)
|
STARSHIP_END_TIME=$(::STARSHIP:: time)
|
||||||
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME))
|
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME))
|
||||||
PS1="$(::STARSHIP:: prompt --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS" --cmd-duration=$STARSHIP_DURATION)"
|
PS1="$(::STARSHIP:: prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS" --cmd-duration=$STARSHIP_DURATION)"
|
||||||
unset STARSHIP_START_TIME
|
unset STARSHIP_START_TIME
|
||||||
else
|
else
|
||||||
PS1="$(::STARSHIP:: prompt --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS")"
|
PS1="$(::STARSHIP:: prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS")"
|
||||||
fi
|
fi
|
||||||
STARSHIP_PREEXEC_READY=true # Signal that we can safely restart the timer
|
STARSHIP_PREEXEC_READY=true # Signal that we can safely restart the timer
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,11 @@ function fish_prompt
|
||||||
# Account for changes in variable name between v2.7 and v3.0
|
# Account for changes in variable name between v2.7 and v3.0
|
||||||
set STARSHIP_DURATION "$CMD_DURATION$cmd_duration"
|
set STARSHIP_DURATION "$CMD_DURATION$cmd_duration"
|
||||||
set STARSHIP_JOBS (count (jobs -p))
|
set STARSHIP_JOBS (count (jobs -p))
|
||||||
::STARSHIP:: prompt --status=$STARSHIP_CMD_STATUS --pipestatus=$pipestatus --keymap=$STARSHIP_KEYMAP --cmd-duration=$STARSHIP_DURATION --jobs=$STARSHIP_JOBS
|
::STARSHIP:: prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus=$pipestatus --keymap=$STARSHIP_KEYMAP --cmd-duration=$STARSHIP_DURATION --jobs=$STARSHIP_JOBS
|
||||||
end
|
end
|
||||||
|
|
||||||
function fish_right_prompt
|
function fish_right_prompt
|
||||||
::STARSHIP:: prompt --right --status=$STARSHIP_CMD_STATUS --pipestatus=$pipestatus --keymap=$STARSHIP_KEYMAP --cmd-duration=$STARSHIP_DURATION --jobs=$STARSHIP_JOBS
|
::STARSHIP:: prompt --right --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus=$pipestatus --keymap=$STARSHIP_KEYMAP --cmd-duration=$STARSHIP_DURATION --jobs=$STARSHIP_JOBS
|
||||||
end
|
end
|
||||||
|
|
||||||
# Disable virtualenv prompt, it breaks starship
|
# Disable virtualenv prompt, it breaks starship
|
||||||
|
|
|
@ -74,6 +74,7 @@ function global:prompt {
|
||||||
"prompt"
|
"prompt"
|
||||||
"--path=$($cwd.Path)",
|
"--path=$($cwd.Path)",
|
||||||
"--logical-path=$($cwd.LogicalPath)",
|
"--logical-path=$($cwd.LogicalPath)",
|
||||||
|
"--terminal-width=$($Host.UI.RawUI.WindowSize.Width)",
|
||||||
"--jobs=$($jobs)"
|
"--jobs=$($jobs)"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -91,5 +91,6 @@ export STARSHIP_SESSION_KEY=${STARSHIP_SESSION_KEY:0:16}; # Trim to 16-digits if
|
||||||
VIRTUAL_ENV_DISABLE_PROMPT=1
|
VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||||
|
|
||||||
setopt promptsubst
|
setopt promptsubst
|
||||||
PROMPT='$(::STARSHIP:: prompt --keymap="$KEYMAP" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="$STARSHIP_DURATION" --jobs="$STARSHIP_JOBS_COUNT")'
|
PROMPT='$(::STARSHIP:: prompt --terminal-width="$COLUMNS" --keymap="$KEYMAP" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="$STARSHIP_DURATION" --jobs="$STARSHIP_JOBS_COUNT")'
|
||||||
RPROMPT='$(::STARSHIP:: prompt --right --keymap="$KEYMAP" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="$STARSHIP_DURATION" --jobs="$STARSHIP_JOBS_COUNT")'
|
RPROMPT='$(::STARSHIP:: prompt --right --terminal-width="$COLUMNS" --keymap="$KEYMAP" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="$STARSHIP_DURATION" --jobs="$STARSHIP_JOBS_COUNT")'
|
||||||
|
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -30,6 +30,13 @@ fn main() {
|
||||||
.long_help("Bash and Zsh supports returning codes for each process in a pipeline.")
|
.long_help("Bash and Zsh supports returning codes for each process in a pipeline.")
|
||||||
.multiple(true);
|
.multiple(true);
|
||||||
|
|
||||||
|
let terminal_width_arg = Arg::with_name("terminal_width")
|
||||||
|
.short("w")
|
||||||
|
.long("terminal-width")
|
||||||
|
.value_name("TERMINAL_WIDTH")
|
||||||
|
.help("The width of the current interactive terminal.")
|
||||||
|
.takes_value(true);
|
||||||
|
|
||||||
let path_arg = Arg::with_name("path")
|
let path_arg = Arg::with_name("path")
|
||||||
.short("p")
|
.short("p")
|
||||||
.long("path")
|
.long("path")
|
||||||
|
@ -107,6 +114,7 @@ fn main() {
|
||||||
)
|
)
|
||||||
.arg(&status_code_arg)
|
.arg(&status_code_arg)
|
||||||
.arg(&pipestatus_arg)
|
.arg(&pipestatus_arg)
|
||||||
|
.arg(&terminal_width_arg)
|
||||||
.arg(&path_arg)
|
.arg(&path_arg)
|
||||||
.arg(&logical_path_arg)
|
.arg(&logical_path_arg)
|
||||||
.arg(&cmd_duration_arg)
|
.arg(&cmd_duration_arg)
|
||||||
|
@ -130,6 +138,7 @@ fn main() {
|
||||||
)
|
)
|
||||||
.arg(&status_code_arg)
|
.arg(&status_code_arg)
|
||||||
.arg(&pipestatus_arg)
|
.arg(&pipestatus_arg)
|
||||||
|
.arg(&terminal_width_arg)
|
||||||
.arg(&path_arg)
|
.arg(&path_arg)
|
||||||
.arg(&logical_path_arg)
|
.arg(&logical_path_arg)
|
||||||
.arg(&cmd_duration_arg)
|
.arg(&cmd_duration_arg)
|
||||||
|
@ -187,6 +196,7 @@ fn main() {
|
||||||
.about("Explains the currently showing modules")
|
.about("Explains the currently showing modules")
|
||||||
.arg(&status_code_arg)
|
.arg(&status_code_arg)
|
||||||
.arg(&pipestatus_arg)
|
.arg(&pipestatus_arg)
|
||||||
|
.arg(&terminal_width_arg)
|
||||||
.arg(&path_arg)
|
.arg(&path_arg)
|
||||||
.arg(&logical_path_arg)
|
.arg(&logical_path_arg)
|
||||||
.arg(&cmd_duration_arg)
|
.arg(&cmd_duration_arg)
|
||||||
|
@ -198,6 +208,7 @@ fn main() {
|
||||||
.about("Prints timings of all active modules")
|
.about("Prints timings of all active modules")
|
||||||
.arg(&status_code_arg)
|
.arg(&status_code_arg)
|
||||||
.arg(&pipestatus_arg)
|
.arg(&pipestatus_arg)
|
||||||
|
.arg(&terminal_width_arg)
|
||||||
.arg(&path_arg)
|
.arg(&path_arg)
|
||||||
.arg(&logical_path_arg)
|
.arg(&logical_path_arg)
|
||||||
.arg(&cmd_duration_arg)
|
.arg(&cmd_duration_arg)
|
||||||
|
|
Loading…
Reference in New Issue