Skip to content

Commit

Permalink
trim PR title when too large for terminal in gm gh pr checkout (#129)
Browse files Browse the repository at this point in the history
`input list` has trouble
- scrolling when one line is too large
- treating ANSI sequences (they match, e.g the `m` in `\0[m`)

this PR computes custom lines that are trimmed to the size of the
terminal and don't use ANSI coloring 🤔

## test it
- run
```nushell
tk run --interactive --sugar ["github"]
```
- go to a directory with remote PR, e.g. `nushell/nushell`
- run
```nushell
gm gh pr checkout
```
  • Loading branch information
amtoine authored Dec 6, 2023
1 parent f91b743 commit ea478a9
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/nu-git-manager-sugar/github.nu
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,32 @@ export def "gm gh pr checkout" [] {
return
}

# NOTE: `input list` has trouble with large inputs...
# this part of the command makes sure each line fits in the terminal width nicely.
#
# related to https://github.com/nushell/nushell/issues/11245
let width = $prs
| each { {
author: ($in.author | str length),
id: ($in.id | into string | str length),
title: ($in.title | str length),
}}
| math max
let prs = $prs
| update author { fill --alignment right --character ' ' --width $width.author }
| update id { fill --alignment right --character ' ' --width $width.id }
| update title { fill --alignment left --character ' ' --width $width.title }
| each {
$"($in.author) \(($in.id)\): ($in.title)" | str substring ..((term size).columns - 2)
}

let res = $prs | input list --fuzzy
if $res == null {
log info "user chose to exit"
return
}

^gh pr checkout $res.id
^gh pr checkout (
$res | ansi strip | parse "{author} ({number}): {title}" | into record | get number
)
}

0 comments on commit ea478a9

Please sign in to comment.