1/** 2 * The terminal header's progress indicator. 3 * 4 * Draws the OSC 9;4 state a running program reported (see 5 * docs/archive/terminal/terminal-progress-plan.md) into a slim bar plus a percentage. This is 6 * the *view* only: it knows the five states and how each looks, and nothing 7 * about addons, notifications, timers or when a run counts as finished. That 8 * policy stays in the controller, which is what keeps this file testable by 9 * eye and the controller from growing another eighty lines. 10 * 11 * The markup it drives is static, in `templates/components/Terminal.html.twig`, 12 * and its presentation is static too, in `_widgets.css` â the same split the 13 * search bar and the copy popups use. What is dynamic, and therefore lives 14 * here, is the fill width, the tone class, the label and the ARIA state. 15 * 16 * It carries no strings: like `notify.ts`, the already-translated labels are 17 * handed in by the caller. 18 */ /** The five ConEmu progress states, as `@xterm/addon-progress` reports them. */ function _class_call_check(instance, Constructor) { 19 if (!(instance instanceof Constructor)) { 20 throw new TypeError("Cannot call a class as a function"); 21 } 22} 23function _defineProperties(target, props) { 24 for(var i = 0; i < props.length; i++){ 25 var descriptor = props[i]; 26 descriptor.enumerable = descriptor.enumerable || false; 27 descriptor.configurable = true; 28 if ("value" in descriptor) descriptor.writable = true; 29 Object.defineProperty(target, descriptor.key, descriptor); 30 } 31} 32function _create_class(Constructor, protoProps, staticProps) { 33 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 34 if (staticProps) _defineProperties(Constructor, staticProps); 35 return Constructor; 36} 37function _define_property(obj, key, value) { 38 if (key in obj) { 39 Object.defineProperty(obj, key, { 40 value: value, 41 enumerable: true, 42 configurable: true, 43 writable: true 44 }); 45 } else { 46 obj[key] = value; 47 } 48 return obj; 49} 50/** State â the modifier class that colours the bar and drives the animation. */ var STATE_CLASS = { 51 0: "", 52 1: "is-normal", 53 2: "is-error", 54 3: "is-indeterminate", 55 4: "is-paused" 56}; 57var HeaderProgressView = /*#__PURE__*/ function() { 58 "use strict"; 59 function HeaderProgressView(root, labels) { 60 _class_call_check(this, HeaderProgressView); 61 _define_property(this, "labels", void 0); 62 _define_property(this, "root", void 0); 63 _define_property(this, "fill", void 0); 64 _define_property(this, "track", void 0); 65 _define_property(this, "value", void 0); 66 this.labels = labels; 67 this.root = root; 68 this.fill = root.querySelector(".el-term-progress-fill"); 69 this.track = root.querySelector(".el-term-progress-track"); 70 this.value = root.querySelector(".el-term-progress-value"); 71 } 72 _create_class(HeaderProgressView, [ 73 { 74 key: "render", 75 value: function render(state, value) { 76 if (!this.root) { 77 return; 78 } 79 if (state === 0) { 80 this.root.hidden = true; 81 return; 82 } 83 this.root.hidden = false; 84 this.root.className = "el-term-progress ".concat(STATE_CLASS[state]); 85 // Indeterminate has no percentage to show, and no percentage to 86 // announce either â the fill width is owned by the CSS animation 87 // there, so leave it alone rather than fighting it. 88 var determinate = state !== 3; 89 if (this.fill && determinate) { 90 this.fill.style.width = "".concat(Math.min(Math.max(value, 0), 100), "%"); 91 } else if (this.fill) { 92 this.fill.style.width = ""; 93 } 94 if (this.value) { 95 this.value.textContent = determinate ? "".concat(value, "%") : ""; 96 } 97 // The tone is a colour, and colour is not a channel everyone has. 98 // The accessible name says which of the three situations this is, and 99 // is also what the hover tooltip shows. 100 var situation = state === 2 ? this.labels.errored : state === 4 ? this.labels.paused : this.labels.running; 101 var hint = this.labels.hint.split("{state}").join(situation); 102 this.root.setAttribute("aria-label", hint); 103 this.root.title = hint; 104 if (this.track) { 105 this.track.setAttribute("aria-valuetext", determinate ? "".concat(value, "% â ").concat(situation) : situation); 106 if (determinate) { 107 this.track.setAttribute("aria-valuenow", String(value)); 108 } else { 109 // An absent `aria-valuenow` is how a progressbar says 110 // "indeterminate"; a zero would say "nothing has happened". 111 this.track.removeAttribute("aria-valuenow"); 112 } 113 } 114 } 115 }, 116 { 117 key: "dispose", 118 value: function dispose() { 119 if (this.root) { 120 this.root.hidden = true; 121 this.root = null; 122 } 123 } 124 } 125 ]); 126 return HeaderProgressView; 127}(); 128/** 129 * Bind a view to the header element the component rendered. 130 * 131 * Returns null when the element is absent, which is the normal case: the 132 * markup only exists where the `progress` prop is on. 133 */ export function createProgressView(root, labels) { 134 return root ? new HeaderProgressView(root, labels) : null; 135}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.