* Parse the given line of output from Git, returns either an `IGitProgress` * instance if the line could successfully be parsed as a Git progress * event whose title was registered with this parser or an `IGitOutput` * instance if the line couldn't be parsed or if the title wasn't * regi
(line: string)
| 213 | * registered with the parser. |
| 214 | */ |
| 215 | public parse(line: string): IGitProgress | IGitOutput { |
| 216 | // In case we're parsing hook output or similar we want to |
| 217 | // strip out any control characters that may be present. IGitProgress |
| 218 | // is supposed to be readable text that can be used in tooltips and such. |
| 219 | const text = stripVTControlCharacters(line) |
| 220 | const progress = parse(text) |
| 221 | |
| 222 | if (!progress) { |
| 223 | return { kind: 'context', text, percent: this.lastPercent } |
| 224 | } |
| 225 | |
| 226 | let percent = 0 |
| 227 | |
| 228 | for (let i = 0; i < this.steps.length; i++) { |
| 229 | const step = this.steps[i] |
| 230 | |
| 231 | if (i >= this.stepIndex && progress.title === step.title) { |
| 232 | if (progress.total) { |
| 233 | percent += step.weight * (progress.value / progress.total) |
| 234 | } |
| 235 | |
| 236 | this.stepIndex = i |
| 237 | this.lastPercent = percent |
| 238 | |
| 239 | return { kind: 'progress', percent, details: progress } |
| 240 | } else { |
| 241 | percent += step.weight |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return { kind: 'context', text, percent: this.lastPercent } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | const percentRe = /^(\d{1,3})% \((\d+)\/(\d+)\)$/ |