CH-J SM Mobilespráva serverů přes SSH
Menu
Vydané zdroje

CH-J SM Mobile

Procházejte adresáře a soubory konkrétního vydání aplikace.

Stáhnout zdroje ZIP
CH-J / SM Mobile 175 souborů
sm-mobile-20261016T185235Z-8e93ecc1b59a Přidáno: · Sestaveno:
languages.dart Přidáno: Datum není evidováno 14,7 KB · 411 řádků
Kód Stáhnout soubor
1import 'dart:typed_data';
2import 'package:re_highlight/languages/apache.dart';
3import 'package:re_highlight/languages/bash.dart';
4import 'package:re_highlight/languages/c.dart';
5import 'package:re_highlight/languages/cmake.dart';
6import 'package:re_highlight/languages/cpp.dart';
7import 'package:re_highlight/languages/csharp.dart';
8import 'package:re_highlight/languages/css.dart';
9import 'package:re_highlight/languages/dart.dart';
10import 'package:re_highlight/languages/diff.dart';
11import 'package:re_highlight/languages/dockerfile.dart';
12import 'package:re_highlight/languages/dos.dart';
13import 'package:re_highlight/languages/go.dart';
14import 'package:re_highlight/languages/gradle.dart';
15import 'package:re_highlight/languages/graphql.dart';
16import 'package:re_highlight/languages/ini.dart';
17import 'package:re_highlight/languages/java.dart';
18import 'package:re_highlight/languages/javascript.dart';
19import 'package:re_highlight/languages/json.dart';
20import 'package:re_highlight/languages/kotlin.dart';
21import 'package:re_highlight/languages/less.dart';
22import 'package:re_highlight/languages/lua.dart';
23import 'package:re_highlight/languages/makefile.dart';
24import 'package:re_highlight/languages/markdown.dart';
25import 'package:re_highlight/languages/nginx.dart';
26import 'package:re_highlight/languages/perl.dart';
27import 'package:re_highlight/languages/php.dart';
28import 'package:re_highlight/languages/powershell.dart';
29import 'package:re_highlight/languages/properties.dart';
30import 'package:re_highlight/languages/protobuf.dart';
31import 'package:re_highlight/languages/python.dart';
32import 'package:re_highlight/languages/ruby.dart';
33import 'package:re_highlight/languages/rust.dart';
34import 'package:re_highlight/languages/scss.dart';
35import 'package:re_highlight/languages/sql.dart';
36import 'package:re_highlight/languages/swift.dart';
37import 'package:re_highlight/languages/typescript.dart';
38import 'package:re_highlight/languages/xml.dart';
39import 'package:re_highlight/languages/yaml.dart';
40import 'package:re_highlight/re_highlight.dart' show Mode;
42/// A syntax the editor offers. [grammar] is the Re-Highlight grammar used
43/// to colour it; null means plain text (no grammar exists for it, and none
44/// is pretended).
45class Syntax {
46 final String id, label;
47 final String? grammar;
48 const Syntax(this.id, this.label, [this.grammar]);
49 bool get highlighted => grammar != null;
52/// Grammars bundled from Re-Highlight. Embedded languages (CSS/JS inside
53/// HTML, HTML around PHP) are not coloured: the editor highlights with
54/// exactly one grammar.
55final Map<String, Mode> grammars = {
56 'apache': langApache,
57 'bash': langBash,
58 'c': langC,
59 'cmake': langCmake,
60 'cpp': langCpp,
61 'csharp': langCsharp,
62 'css': langCss,
63 'dart': langDart,
64 'diff': langDiff,
65 'dockerfile': langDockerfile,
66 'dos': langDos,
67 'go': langGo,
68 'gradle': langGradle,
69 'graphql': langGraphql,
70 'ini': langIni,
71 'java': langJava,
72 'javascript': langJavascript,
73 'json': langJson,
74 'kotlin': langKotlin,
75 'less': langLess,
76 'lua': langLua,
77 'makefile': langMakefile,
78 'markdown': langMarkdown,
79 'nginx': langNginx,
80 'perl': langPerl,
81 'php': langPhp,
82 'powershell': langPowershell,
83 'properties': langProperties,
84 'protobuf': langProtobuf,
85 'python': langPython,
86 'ruby': langRuby,
87 'rust': langRust,
88 'scss': langScss,
89 'sql': langSql,
90 'swift': langSwift,
91 'typescript': langTypescript,
92 'xml': langXml,
93 'yaml': langYaml,
94};
96const plainText = Syntax('text', 'Text');
98/// Every syntax the user can pick by hand, by label.
99const syntaxes = <Syntax>[
100 plainText,
101 Syntax('apache', 'Apache config', 'apache'),
102 Syntax('bash', 'Shell (Bash/sh/zsh)', 'bash'),
103 Syntax('batch', 'Batch (cmd)', 'dos'),
104 Syntax('c', 'C', 'c'),
105 Syntax('cpp', 'C++', 'cpp'),
106 Syntax('csharp', 'C#', 'csharp'),
107 Syntax('cmake', 'CMake', 'cmake'),
108 Syntax('css', 'CSS', 'css'),
109 Syntax('csv', 'CSV / TSV'),
110 Syntax('dart', 'Dart', 'dart'),
111 Syntax('diff', 'Diff / patch', 'diff'),
112 Syntax('dockerfile', 'Dockerfile', 'dockerfile'),
113 Syntax('env', '.env', 'properties'),
114 Syntax('fish', 'fish'),
115 Syntax('go', 'Go', 'go'),
116 Syntax('gradle', 'Gradle', 'gradle'),
117 Syntax('graphql', 'GraphQL', 'graphql'),
118 Syntax('hcl', 'Terraform (HCL)'),
119 Syntax('html', 'HTML', 'xml'),
120 Syntax('ini', 'INI / config', 'ini'),
121 Syntax('java', 'Java', 'java'),
122 Syntax('javascript', 'JavaScript', 'javascript'),
123 Syntax('json', 'JSON', 'json'),
124 Syntax('jsonl', 'JSON Lines', 'json'),
125 Syntax('kotlin', 'Kotlin', 'kotlin'),
126 Syntax('less', 'Less', 'less'),
127 Syntax('log', 'Log'),
128 Syntax('lua', 'Lua', 'lua'),
129 Syntax('makefile', 'Makefile', 'makefile'),
130 Syntax('markdown', 'Markdown', 'markdown'),
131 Syntax('nginx', 'NGINX', 'nginx'),
132 Syntax('perl', 'Perl', 'perl'),
133 Syntax('php', 'PHP', 'php'),
134 Syntax('plist', 'Property list (XML)', 'xml'),
135 Syntax('powershell', 'PowerShell', 'powershell'),
136 Syntax('properties', 'Properties', 'properties'),
137 Syntax('protobuf', 'Protocol Buffers', 'protobuf'),
138 Syntax('python', 'Python', 'python'),
139 Syntax('ruby', 'Ruby', 'ruby'),
140 Syntax('rust', 'Rust', 'rust'),
141 Syntax('sass', 'Sass (indented)'),
142 Syntax('scss', 'SCSS', 'scss'),
143 Syntax('sql', 'SQL', 'sql'),
144 Syntax('sshconfig', 'SSH config'),
145 Syntax('svg', 'SVG (XML)', 'xml'),
146 Syntax('swift', 'Swift', 'swift'),
147 Syntax('systemd', 'systemd unit', 'ini'),
148 Syntax('toml', 'TOML', 'ini'),
149 Syntax('typescript', 'TypeScript', 'typescript'),
150 Syntax('xml', 'XML', 'xml'),
151 Syntax('yaml', 'YAML', 'yaml'),
152 Syntax('pem', 'PEM / key / certificate'),
153 Syntax('unixconfig', 'Unix config'),
154];
156Syntax syntaxById(String id) =>
157 syntaxes.firstWhere((s) => s.id == id, orElse: () => plainText);
159const _byName = <String, String>{
160 'dockerfile': 'dockerfile',
161 'containerfile': 'dockerfile',
162 'makefile': 'makefile',
163 'gnumakefile': 'makefile',
164 'cmakelists.txt': 'cmake',
165 'nginx.conf': 'nginx',
166 'httpd.conf': 'apache',
167 'apache2.conf': 'apache',
168 '.htaccess': 'apache',
169 '.htpasswd': 'unixconfig',
170 'sshd_config': 'sshconfig',
171 'ssh_config': 'sshconfig',
172 '.bashrc': 'bash',
173 '.bash_profile': 'bash',
174 '.bash_aliases': 'bash',
175 '.bash_logout': 'bash',
176 '.zshrc': 'bash',
177 '.zprofile': 'bash',
178 '.profile': 'bash',
179 '.gitignore': 'unixconfig',
180 '.dockerignore': 'unixconfig',
181 '.gitattributes': 'unixconfig',
182 '.gitconfig': 'ini',
183 '.editorconfig': 'ini',
184 '.npmrc': 'ini',
185 '.env': 'env',
186 'hosts': 'unixconfig',
187 'fstab': 'unixconfig',
188 'crontab': 'unixconfig',
189 'authorized_keys': 'unixconfig',
190 'known_hosts': 'unixconfig',
191};
193const _byExtension = <String, String>{
194 'html': 'html', 'htm': 'html', 'xhtml': 'html', //
195 'php': 'php', 'phtml': 'php', 'php5': 'php',
196 'css': 'css', 'scss': 'scss', 'sass': 'sass', 'less': 'less',
197 'js': 'javascript', 'mjs': 'javascript', 'cjs': 'javascript',
198 'jsx': 'javascript',
199 'ts': 'typescript', 'tsx': 'typescript',
200 'json': 'json', 'jsonc': 'json', 'jsonl': 'jsonl', 'ndjson': 'jsonl',
201 'ipynb': 'json',
202 'xml': 'xml', 'xsd': 'xml', 'xsl': 'xml', 'xslt': 'xml',
203 'plist': 'plist', 'svg': 'svg',
204 'yaml': 'yaml', 'yml': 'yaml',
205 'md': 'markdown', 'markdown': 'markdown',
206 'py': 'python', 'pyw': 'python',
207 'dart': 'dart', 'java': 'java', 'kt': 'kotlin', 'kts': 'kotlin',
208 'swift': 'swift', 'rs': 'rust', 'go': 'go',
209 'c': 'c', 'h': 'c',
210 'cpp': 'cpp', 'hpp': 'cpp', 'cc': 'cpp', 'cxx': 'cpp', 'hh': 'cpp',
211 'cs': 'csharp', 'rb': 'ruby', 'pl': 'perl', 'pm': 'perl', 'lua': 'lua',
212 'ps1': 'powershell', 'psm1': 'powershell',
213 'sh': 'bash', 'bash': 'bash', 'zsh': 'bash', 'fish': 'fish',
214 'sql': 'sql', 'graphql': 'graphql', 'gql': 'graphql',
215 'conf': 'ini', 'config': 'ini', 'cfg': 'ini', 'ini': 'ini',
216 'properties': 'properties', 'env': 'env', 'toml': 'toml',
217 'service': 'systemd', 'timer': 'systemd', 'socket': 'systemd',
218 'mount': 'systemd', 'target': 'systemd', 'path': 'systemd',
219 'desktop': 'systemd',
220 'txt': 'text', 'log': 'log', 'csv': 'csv', 'tsv': 'csv',
221 'diff': 'diff', 'patch': 'diff',
222 'pem': 'pem', 'crt': 'pem', 'cer': 'pem', 'pub': 'pem', 'csr': 'pem',
223 'key': 'pem', 'asc': 'pem', 'gpg': 'pem',
224 'tf': 'hcl', 'tfvars': 'hcl',
225 'gradle': 'gradle', 'proto': 'protobuf',
226 'bat': 'batch', 'cmd': 'batch',
227};
229String _base(String name) {
230 final slash = name.lastIndexOf('/');
231 return slash < 0 ? name : name.substring(slash + 1);
234String extensionOf(String name) {
235 final base = _base(name);
236 final dot = base.lastIndexOf('.');
237 return dot <= 0 ? '' : base.substring(dot + 1).toLowerCase();
240/// Picks the syntax for a file: exact name first, then extension, then the
241/// shebang line, then a look at the content. Unknown files are plain text.
242Syntax detectSyntax(String path, {String? content}) {
243 final base = _base(path);
244 final lower = base.toLowerCase();
245 final byName = _byName[lower];
246 if (byName != null) return syntaxById(byName);
247 if (lower.startsWith('dockerfile.')) return syntaxById('dockerfile');
248 if (lower.startsWith('.env.')) return syntaxById('env');
249 if (path.endsWith('.ssh/config')) return syntaxById('sshconfig');
250 if (lower.endsWith('.conf') &&
251 (path.contains('/nginx/') || lower.startsWith('nginx'))) {
252 return syntaxById('nginx');
253 }
254 if (lower.endsWith('.conf') &&
255 (path.contains('/apache2/') || path.contains('/httpd/'))) {
256 return syntaxById('apache');
257 }
258 final byExtension = _byExtension[extensionOf(base)];
259 if (byExtension != null) return syntaxById(byExtension);
260 if (content != null) {
261 final first = content.split('\n').first.trim();
262 if (first.startsWith('#!')) {
263 for (final (word, id) in const [
264 ('python', 'python'),
265 ('node', 'javascript'),
266 ('deno', 'typescript'),
267 ('perl', 'perl'),
268 ('ruby', 'ruby'),
269 ('php', 'php'),
270 ('fish', 'fish'),
271 ('pwsh', 'powershell'),
272 ('bash', 'bash'),
273 ('zsh', 'bash'),
274 ('/sh', 'bash'),
275 (' sh', 'bash'),
276 ]) {
277 if (first.contains(word)) return syntaxById(id);
278 }
279 }
280 final start = content.trimLeft();
281 if (start.startsWith('<?xml')) return syntaxById('xml');
282 if (start.toLowerCase().startsWith('<!doctype html')) {
283 return syntaxById('html');
284 }
285 if (start.startsWith('<?php')) return syntaxById('php');
286 if (start.startsWith('---\n') || start.startsWith('%YAML')) {
287 return syntaxById('yaml');
288 }
289 if (start.startsWith('[Unit]') || start.startsWith('[Service]')) {
290 return syntaxById('systemd');
291 }
292 if (start.startsWith('-----BEGIN ')) return syntaxById('pem');
293 }
294 return plainText;
297/// How a file is opened.
298enum FileKind {
299 text,
300 image,
301 svg,
302 pdf,
303 office,
304 archive,
305 audio,
306 video,
307 notebook,
308 certificate,
309 binary,
312const _kinds = <String, FileKind>{
313 'png': FileKind.image, 'jpg': FileKind.image, 'jpeg': FileKind.image, //
314 'gif': FileKind.image, 'webp': FileKind.image, 'bmp': FileKind.image,
315 'heic': FileKind.image, 'heif': FileKind.image, 'ico': FileKind.image,
316 'svg': FileKind.svg,
317 'pdf': FileKind.pdf,
318 'doc': FileKind.office, 'docx': FileKind.office, 'xls': FileKind.office,
319 'xlsx': FileKind.office, 'ppt': FileKind.office, 'pptx': FileKind.office,
320 'odt': FileKind.office, 'ods': FileKind.office, 'odp': FileKind.office,
321 'rtf': FileKind.office, 'pages': FileKind.office,
322 'numbers': FileKind.office, 'key': FileKind.certificate,
323 'zip': FileKind.archive, 'tar': FileKind.archive, 'gz': FileKind.archive,
324 'tgz': FileKind.archive, 'bz2': FileKind.archive, 'tbz2': FileKind.archive,
325 'xz': FileKind.archive, 'txz': FileKind.archive, '7z': FileKind.archive,
326 'rar': FileKind.archive, 'jar': FileKind.archive, 'apk': FileKind.archive,
327 'ipa': FileKind.archive, 'aab': FileKind.archive,
328 'mp3': FileKind.audio, 'm4a': FileKind.audio, 'aac': FileKind.audio,
329 'wav': FileKind.audio, 'flac': FileKind.audio, 'ogg': FileKind.audio,
330 'opus': FileKind.audio, 'aiff': FileKind.audio,
331 'mp4': FileKind.video, 'mov': FileKind.video, 'm4v': FileKind.video,
332 'webm': FileKind.video, 'mkv': FileKind.video, 'avi': FileKind.video,
333 '3gp': FileKind.video,
334 'ipynb': FileKind.notebook,
335 'pem': FileKind.certificate, 'crt': FileKind.certificate,
336 'cer': FileKind.certificate, 'der': FileKind.certificate,
337 'p12': FileKind.certificate, 'pfx': FileKind.certificate,
338 'csr': FileKind.certificate, 'pub': FileKind.certificate,
339 'asc': FileKind.certificate, 'gpg': FileKind.certificate,
340};
342/// The viewer for [name]; [head] (the first bytes) separates text from
343/// binary for unknown extensions.
344FileKind fileKind(String name, {Uint8List? head}) {
345 final kind = _kinds[extensionOf(name)];
346 if (kind != null) return kind;
347 if (head != null && head.isNotEmpty) {
348 if (_magic(head, const [0x89, 0x50, 0x4e, 0x47])) return FileKind.image;
349 if (_magic(head, const [0xff, 0xd8, 0xff])) return FileKind.image;
350 if (_magic(head, const [0x47, 0x49, 0x46, 0x38])) return FileKind.image;
351 if (_magic(head, const [0x25, 0x50, 0x44, 0x46])) return FileKind.pdf;
352 if (_magic(head, const [0x50, 0x4b, 0x03, 0x04])) return FileKind.archive;
353 if (_magic(head, const [0x1f, 0x8b])) return FileKind.archive;
354 }
355 return FileKind.text;
358bool _magic(Uint8List b, List<int> m) {
359 if (b.length < m.length) return false;
360 for (var i = 0; i < m.length; i++) {
361 if (b[i] != m[i]) return false;
362 }
363 return true;
366/// MIME type for sharing, saving and system viewers.
367String mimeOf(String name) => switch (extensionOf(name)) {
368 'txt' || 'log' || 'conf' || 'cfg' || 'ini' || '' => 'text/plain',
369 'html' || 'htm' => 'text/html',
370 'css' => 'text/css',
371 'csv' => 'text/csv',
372 'js' || 'mjs' => 'text/javascript',
373 'json' => 'application/json',
374 'xml' => 'application/xml',
375 'yaml' || 'yml' => 'application/yaml',
376 'md' => 'text/markdown',
377 'png' => 'image/png',
378 'jpg' || 'jpeg' => 'image/jpeg',
379 'gif' => 'image/gif',
380 'webp' => 'image/webp',
381 'bmp' => 'image/bmp',
382 'heic' => 'image/heic',
383 'heif' => 'image/heif',
384 'svg' => 'image/svg+xml',
385 'pdf' => 'application/pdf',
386 'doc' => 'application/msword',
387 'docx' =>
388 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
389 'xls' => 'application/vnd.ms-excel',
390 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
391 'ppt' => 'application/vnd.ms-powerpoint',
392 'pptx' =>
393 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
394 'odt' => 'application/vnd.oasis.opendocument.text',
395 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
396 'odp' => 'application/vnd.oasis.opendocument.presentation',
397 'rtf' => 'application/rtf',
398 'zip' => 'application/zip',
399 'gz' || 'tgz' => 'application/gzip',
400 'tar' => 'application/x-tar',
401 'mp3' => 'audio/mpeg',
402 'm4a' || 'aac' => 'audio/mp4',
403 'wav' => 'audio/wav',
404 'flac' => 'audio/flac',
405 'ogg' || 'opus' => 'audio/ogg',
406 'mp4' || 'm4v' => 'video/mp4',
407 'mov' => 'video/quicktime',
408 'webm' => 'video/webm',
409 'mkv' => 'video/x-matroska',
410 _ => 'application/octet-stream',
411};
SHA-256b5f3e00d877b056de93c5cff3f22b7e6c83a6f7ba50f0e075ab61d228c20f9d0

CH-J Proprietary Software License 1.14 · Zdroje jsou zveřejněny pod CH-J Proprietary Software License 1.14. Jejich dostupnost nemění licenční podmínky ani neposkytuje další oprávnění.

SHA-256 archivu46e427a43e87af091004f36145590bda8fe90086dfb0f631afeb5029fb0b5655
Soubory