cool-retro-term

Форк
0
122 строки · 3.5 Кб
1
/*******************************************************************************
2
* Copyright (c) 2013-2021 "Filippo Scognamiglio"
3
* https://github.com/Swordfish90/cool-retro-term
4
*
5
* This file is part of cool-retro-term.
6
*
7
* cool-retro-term is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
*******************************************************************************/
20

21
.pragma library
22
function clamp(x, min, max) {
23
    if (x <= min)
24
        return min;
25
    if (x >= max)
26
        return max;
27
    return x;
28
}
29

30
function lint(a, b, t) {
31
    return (1 - t) * a + (t) * b;
32
}
33

34
function mix(c1, c2, alpha) {
35
    return Qt.rgba(c1.r * alpha + c2.r * (1-alpha),
36
                   c1.g * alpha + c2.g * (1-alpha),
37
                   c1.b * alpha + c2.b * (1-alpha),
38
                   c1.a * alpha + c2.a * (1-alpha))
39
}
40

41
function smoothstep(min, max, value) {
42
    let x = Math.max(0, Math.min(1, (value - min) / (max - min)));
43
    return x * x * (3 - 2 * x);
44
}
45

46
function strToColor(s){
47
    var r = parseInt(s.substring(1,3), 16) / 256;
48
    var g = parseInt(s.substring(3,5), 16) / 256;
49
    var b = parseInt(s.substring(5,7), 16) / 256;
50
    return Qt.rgba(r, g, b, 1.0);
51
}
52

53
/* Tokenizes a command into program and arguments, taking into account quoted
54
 * strings and backslashes.
55
 * Based on GLib's tokenizer, used by Gnome Terminal
56
 */
57
function tokenizeCommandLine(s){
58
    var args = [];
59
    var currentToken = "";
60
    var quoteChar = "";
61
    var escaped = false;
62
    var nextToken = function() {
63
        args.push(currentToken);
64
        currentToken = "";
65
    }
66
    var appendToCurrentToken = function(c) {
67
        currentToken += c;
68
    }
69

70
    for (var i = 0; i < s.length; i++) {
71

72
        // char followed by backslash, append literally
73
        if (escaped) {
74
            escaped = false;
75
            appendToCurrentToken(s[i]);
76

77
        // char inside quotes, either close or append
78
        } else if (quoteChar) {
79
            escaped = s[i] === '\\';
80
            if (quoteChar === s[i]) {
81
                quoteChar = "";
82
                nextToken();
83
            } else if (!escaped) {
84
                appendToCurrentToken(s[i]);
85
            }
86

87
        // regular char
88
        } else {
89
            escaped = s[i] === '\\';
90
            switch (s[i]) {
91
            case '\\':
92
                // begin escape
93
                break;
94
            case '\n':
95
                // newlines always delimits
96
                nextToken();
97
                break;
98
            case ' ':
99
            case '\t':
100
                // delimit on new whitespace
101
                if (currentToken) {
102
                    nextToken();
103
                }
104
                break;
105
            case '\'':
106
            case '"':
107
                // begin quoted section
108
                quoteChar = s[i];
109
                break;
110
            default:
111
                appendToCurrentToken(s[i]);
112
            }
113
        }
114
    }
115

116
    // ignore last token if broken quotes/backslash
117
    if (currentToken && !escaped && !quoteChar) {
118
        nextToken();
119
    }
120

121
    return args;
122
}
123

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.