| 172 | } |
| 173 | |
| 174 | func (pr *PullRequest) String(config *config.Config) string { |
| 175 | prStatus := pr.StatusString(config) |
| 176 | if pr.Merged { |
| 177 | prStatus = "MERGED" |
| 178 | } |
| 179 | |
| 180 | prInfo := fmt.Sprintf("%3d", pr.Number) |
| 181 | prURL := fmt.Sprintf("https://%s/%s/%s/pull/%d", |
| 182 | config.Repo.GitHubHost, config.Repo.GitHubRepoOwner, config.Repo.GitHubRepoName, pr.Number) |
| 183 | if config.User.ShortPRLink { |
| 184 | // OSC 8 terminal hyperlink: \033]8;;URL\033\\TEXT\033]8;;\033\\ |
| 185 | prInfo = fmt.Sprintf("\033]8;;%s\033\\PR-%d\033]8;;\033\\", prURL, pr.Number) |
| 186 | } else if config.User.ShowPRLink { |
| 187 | prInfo = prURL |
| 188 | } |
| 189 | |
| 190 | if config.User.ShowCommitID { |
| 191 | // Prefer the local commit hash (matches git log) over the remote hash |
| 192 | displayHash := pr.LocalCommitHash |
| 193 | if displayHash == "" { |
| 194 | displayHash = pr.Commit.CommitHash |
| 195 | } |
| 196 | if len(displayHash) >= 8 { |
| 197 | prInfo = displayHash[:8] + " " + prInfo |
| 198 | } else if len(displayHash) > 0 { |
| 199 | prInfo = displayHash + " " + prInfo |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | var mq string |
| 204 | if len(pr.Commits) > 1 { |
| 205 | mq = statusBitIcons(config)["warning"] |
| 206 | } |
| 207 | |
| 208 | if pr.InQueue { |
| 209 | mq = statusBitIcons(config)["pending"] |
| 210 | } |
| 211 | |
| 212 | if mq != "" { |
| 213 | mq += " " |
| 214 | } |
| 215 | |
| 216 | line := fmt.Sprintf("%s %s%s : %s", prStatus, mq, prInfo, pr.Title) |
| 217 | |
| 218 | // trim line to terminal width |
| 219 | terminalWidth, err := terminal.Width() |
| 220 | if err != nil { |
| 221 | terminalWidth = 1000 |
| 222 | } |
| 223 | lineLength := utf8.RuneCountInString(line) |
| 224 | if config.User.ShortPRLink { |
| 225 | // OSC 8 escape sequences are invisible; subtract their length |
| 226 | // The escape overhead is: \033]8;; + URL + \033\\ + \033]8;;\033\\ = 12 + len(URL) |
| 227 | lineLength -= 12 + utf8.RuneCountInString(prURL) |
| 228 | } |
| 229 | if config.User.StatusBitsEmojis { |
| 230 | // each emoji consumes 2 chars in the terminal |
| 231 | lineLength += 4 |