More Filetype information, tweak highlighting colors slightly
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
This commit is contained in:
parent
e84dfa9ba9
commit
6d9d1113f2
@ -9,6 +9,7 @@ export enum FileLang {
|
||||
TypeScript = 'TypeScript',
|
||||
JavaScript = 'JavaScript',
|
||||
CSS = 'CSS',
|
||||
Shell = 'Shell',
|
||||
Plain = 'Plain Text',
|
||||
}
|
||||
|
||||
@ -20,12 +21,15 @@ export interface HighlightingOptions {
|
||||
interface IFileType {
|
||||
readonly name: FileLang;
|
||||
readonly singleLineComment: Option<string>;
|
||||
readonly multiLineCommentStart: Option<string>;
|
||||
readonly multiLineCommentEnd: Option<string>;
|
||||
readonly keywords1: string[];
|
||||
readonly keywords2: string[];
|
||||
readonly hlOptions: HighlightingOptions;
|
||||
get flags(): HighlightingOptions;
|
||||
get primaryKeywords(): string[];
|
||||
get secondaryKeywords(): string[];
|
||||
hasMultilineComments(): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,6 +38,8 @@ interface IFileType {
|
||||
export abstract class AbstractFileType implements IFileType {
|
||||
public readonly name: FileLang = FileLang.Plain;
|
||||
public readonly singleLineComment = None;
|
||||
public readonly multiLineCommentStart: Option<string> = None;
|
||||
public readonly multiLineCommentEnd: Option<string> = None;
|
||||
public readonly keywords1: string[] = [];
|
||||
public readonly keywords2: string[] = [];
|
||||
public readonly hlOptions: HighlightingOptions = {
|
||||
@ -52,6 +58,11 @@ export abstract class AbstractFileType implements IFileType {
|
||||
get secondaryKeywords(): string[] {
|
||||
return this.keywords2;
|
||||
}
|
||||
|
||||
public hasMultilineComments(): boolean {
|
||||
return this.multiLineCommentStart.isSome() &&
|
||||
this.multiLineCommentEnd.isSome();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -65,6 +76,8 @@ const defaultHighlightOptions: HighlightingOptions = {
|
||||
class JavaScriptFile extends AbstractFileType {
|
||||
public readonly name: FileLang = FileLang.JavaScript;
|
||||
public readonly singleLineComment = Some('//');
|
||||
public readonly multiLineCommentStart: Option<string> = Some('/*');
|
||||
public readonly multiLineCommentEnd: Option<string> = Some('*/');
|
||||
public readonly keywords1 = [
|
||||
'break',
|
||||
'case',
|
||||
@ -115,6 +128,13 @@ class JavaScriptFile extends AbstractFileType {
|
||||
'get',
|
||||
'of',
|
||||
'set',
|
||||
'=>',
|
||||
'Number',
|
||||
'String',
|
||||
'Object',
|
||||
'Math',
|
||||
'JSON',
|
||||
'Boolean',
|
||||
];
|
||||
public readonly hlOptions: HighlightingOptions = {
|
||||
...defaultHighlightOptions,
|
||||
@ -123,56 +143,8 @@ class JavaScriptFile extends AbstractFileType {
|
||||
|
||||
class TypeScriptFile extends JavaScriptFile {
|
||||
public readonly name: FileLang = FileLang.TypeScript;
|
||||
public readonly keywords1 = [
|
||||
'break',
|
||||
'case',
|
||||
'catch',
|
||||
'class',
|
||||
'const',
|
||||
'continue',
|
||||
'debugger',
|
||||
'default',
|
||||
'delete',
|
||||
'do',
|
||||
'else',
|
||||
'export',
|
||||
'extends',
|
||||
'false',
|
||||
'finally',
|
||||
'for',
|
||||
'function',
|
||||
'if',
|
||||
'import',
|
||||
'in',
|
||||
'instanceof',
|
||||
'new',
|
||||
'null',
|
||||
'return',
|
||||
'super',
|
||||
'switch',
|
||||
'this',
|
||||
'throw',
|
||||
'true',
|
||||
'try',
|
||||
'typeof',
|
||||
'var',
|
||||
'void',
|
||||
'while',
|
||||
'with',
|
||||
'let',
|
||||
'static',
|
||||
'yield',
|
||||
'await',
|
||||
];
|
||||
public readonly keywords2 = [
|
||||
'arguments',
|
||||
'as',
|
||||
'async',
|
||||
'eval',
|
||||
'from',
|
||||
'get',
|
||||
'of',
|
||||
'set',
|
||||
...super.secondaryKeywords,
|
||||
// Typescript-specific
|
||||
'keyof',
|
||||
'interface',
|
||||
@ -189,9 +161,40 @@ class TypeScriptFile extends JavaScriptFile {
|
||||
];
|
||||
}
|
||||
|
||||
class ShellFile extends AbstractFileType {
|
||||
public readonly name: FileLang = FileLang.Shell;
|
||||
public readonly singleLineComment = Some('#');
|
||||
public readonly keywords1 = [
|
||||
'case',
|
||||
'do',
|
||||
'done',
|
||||
'elif',
|
||||
'else',
|
||||
'esac',
|
||||
'fi',
|
||||
'for',
|
||||
'function',
|
||||
'if',
|
||||
'in',
|
||||
'select',
|
||||
'then',
|
||||
'time',
|
||||
'until',
|
||||
'while',
|
||||
'declare',
|
||||
];
|
||||
public readonly keywords2 = ['set'];
|
||||
public readonly hlOptions: HighlightingOptions = {
|
||||
...defaultHighlightOptions,
|
||||
numbers: false,
|
||||
};
|
||||
}
|
||||
|
||||
class CSSFile extends AbstractFileType {
|
||||
public readonly name: FileLang = FileLang.CSS;
|
||||
public readonly singleLineComment = None;
|
||||
public readonly multiLineCommentStart: Option<string> = Some('/*');
|
||||
public readonly multiLineCommentEnd: Option<string> = Some('*/');
|
||||
public readonly hlOptions: HighlightingOptions = {
|
||||
...defaultHighlightOptions,
|
||||
};
|
||||
@ -204,9 +207,12 @@ class CSSFile extends AbstractFileType {
|
||||
export class FileType extends AbstractFileType {
|
||||
static #fileTypeMap = new Map([
|
||||
['.css', CSSFile],
|
||||
['.json', JavaScriptFile],
|
||||
['.js', JavaScriptFile],
|
||||
['.jsx', JavaScriptFile],
|
||||
['.mjs', JavaScriptFile],
|
||||
['.bash', ShellFile],
|
||||
['.sh', ShellFile],
|
||||
['.ts', TypeScriptFile],
|
||||
['.tsx', TypeScriptFile],
|
||||
]);
|
||||
|
@ -6,6 +6,7 @@ export enum HighlightType {
|
||||
Match,
|
||||
String,
|
||||
SingleLineComment,
|
||||
MultiLineComment,
|
||||
Keyword1,
|
||||
Keyword2,
|
||||
}
|
||||
@ -19,10 +20,11 @@ export function highlightToColor(type: HighlightType): string {
|
||||
return Ansi.color256(21);
|
||||
|
||||
case HighlightType.String:
|
||||
return Ansi.color256(201);
|
||||
return Ansi.color256(45);
|
||||
|
||||
case HighlightType.SingleLineComment:
|
||||
return Ansi.color256(45);
|
||||
case HighlightType.MultiLineComment:
|
||||
return Ansi.color256(201);
|
||||
|
||||
case HighlightType.Keyword1:
|
||||
return Ansi.color256(226);
|
||||
|
Loading…
Reference in New Issue
Block a user