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',
|
TypeScript = 'TypeScript',
|
||||||
JavaScript = 'JavaScript',
|
JavaScript = 'JavaScript',
|
||||||
CSS = 'CSS',
|
CSS = 'CSS',
|
||||||
|
Shell = 'Shell',
|
||||||
Plain = 'Plain Text',
|
Plain = 'Plain Text',
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,12 +21,15 @@ export interface HighlightingOptions {
|
|||||||
interface IFileType {
|
interface IFileType {
|
||||||
readonly name: FileLang;
|
readonly name: FileLang;
|
||||||
readonly singleLineComment: Option<string>;
|
readonly singleLineComment: Option<string>;
|
||||||
|
readonly multiLineCommentStart: Option<string>;
|
||||||
|
readonly multiLineCommentEnd: Option<string>;
|
||||||
readonly keywords1: string[];
|
readonly keywords1: string[];
|
||||||
readonly keywords2: string[];
|
readonly keywords2: string[];
|
||||||
readonly hlOptions: HighlightingOptions;
|
readonly hlOptions: HighlightingOptions;
|
||||||
get flags(): HighlightingOptions;
|
get flags(): HighlightingOptions;
|
||||||
get primaryKeywords(): string[];
|
get primaryKeywords(): string[];
|
||||||
get secondaryKeywords(): string[];
|
get secondaryKeywords(): string[];
|
||||||
|
hasMultilineComments(): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,6 +38,8 @@ interface IFileType {
|
|||||||
export abstract class AbstractFileType implements IFileType {
|
export abstract class AbstractFileType implements IFileType {
|
||||||
public readonly name: FileLang = FileLang.Plain;
|
public readonly name: FileLang = FileLang.Plain;
|
||||||
public readonly singleLineComment = None;
|
public readonly singleLineComment = None;
|
||||||
|
public readonly multiLineCommentStart: Option<string> = None;
|
||||||
|
public readonly multiLineCommentEnd: Option<string> = None;
|
||||||
public readonly keywords1: string[] = [];
|
public readonly keywords1: string[] = [];
|
||||||
public readonly keywords2: string[] = [];
|
public readonly keywords2: string[] = [];
|
||||||
public readonly hlOptions: HighlightingOptions = {
|
public readonly hlOptions: HighlightingOptions = {
|
||||||
@ -52,6 +58,11 @@ export abstract class AbstractFileType implements IFileType {
|
|||||||
get secondaryKeywords(): string[] {
|
get secondaryKeywords(): string[] {
|
||||||
return this.keywords2;
|
return this.keywords2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public hasMultilineComments(): boolean {
|
||||||
|
return this.multiLineCommentStart.isSome() &&
|
||||||
|
this.multiLineCommentEnd.isSome();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -65,6 +76,8 @@ const defaultHighlightOptions: HighlightingOptions = {
|
|||||||
class JavaScriptFile extends AbstractFileType {
|
class JavaScriptFile extends AbstractFileType {
|
||||||
public readonly name: FileLang = FileLang.JavaScript;
|
public readonly name: FileLang = FileLang.JavaScript;
|
||||||
public readonly singleLineComment = Some('//');
|
public readonly singleLineComment = Some('//');
|
||||||
|
public readonly multiLineCommentStart: Option<string> = Some('/*');
|
||||||
|
public readonly multiLineCommentEnd: Option<string> = Some('*/');
|
||||||
public readonly keywords1 = [
|
public readonly keywords1 = [
|
||||||
'break',
|
'break',
|
||||||
'case',
|
'case',
|
||||||
@ -115,6 +128,13 @@ class JavaScriptFile extends AbstractFileType {
|
|||||||
'get',
|
'get',
|
||||||
'of',
|
'of',
|
||||||
'set',
|
'set',
|
||||||
|
'=>',
|
||||||
|
'Number',
|
||||||
|
'String',
|
||||||
|
'Object',
|
||||||
|
'Math',
|
||||||
|
'JSON',
|
||||||
|
'Boolean',
|
||||||
];
|
];
|
||||||
public readonly hlOptions: HighlightingOptions = {
|
public readonly hlOptions: HighlightingOptions = {
|
||||||
...defaultHighlightOptions,
|
...defaultHighlightOptions,
|
||||||
@ -123,56 +143,8 @@ class JavaScriptFile extends AbstractFileType {
|
|||||||
|
|
||||||
class TypeScriptFile extends JavaScriptFile {
|
class TypeScriptFile extends JavaScriptFile {
|
||||||
public readonly name: FileLang = FileLang.TypeScript;
|
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 = [
|
public readonly keywords2 = [
|
||||||
'arguments',
|
...super.secondaryKeywords,
|
||||||
'as',
|
|
||||||
'async',
|
|
||||||
'eval',
|
|
||||||
'from',
|
|
||||||
'get',
|
|
||||||
'of',
|
|
||||||
'set',
|
|
||||||
// Typescript-specific
|
// Typescript-specific
|
||||||
'keyof',
|
'keyof',
|
||||||
'interface',
|
'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 {
|
class CSSFile extends AbstractFileType {
|
||||||
public readonly name: FileLang = FileLang.CSS;
|
public readonly name: FileLang = FileLang.CSS;
|
||||||
public readonly singleLineComment = None;
|
public readonly singleLineComment = None;
|
||||||
|
public readonly multiLineCommentStart: Option<string> = Some('/*');
|
||||||
|
public readonly multiLineCommentEnd: Option<string> = Some('*/');
|
||||||
public readonly hlOptions: HighlightingOptions = {
|
public readonly hlOptions: HighlightingOptions = {
|
||||||
...defaultHighlightOptions,
|
...defaultHighlightOptions,
|
||||||
};
|
};
|
||||||
@ -204,9 +207,12 @@ class CSSFile extends AbstractFileType {
|
|||||||
export class FileType extends AbstractFileType {
|
export class FileType extends AbstractFileType {
|
||||||
static #fileTypeMap = new Map([
|
static #fileTypeMap = new Map([
|
||||||
['.css', CSSFile],
|
['.css', CSSFile],
|
||||||
|
['.json', JavaScriptFile],
|
||||||
['.js', JavaScriptFile],
|
['.js', JavaScriptFile],
|
||||||
['.jsx', JavaScriptFile],
|
['.jsx', JavaScriptFile],
|
||||||
['.mjs', JavaScriptFile],
|
['.mjs', JavaScriptFile],
|
||||||
|
['.bash', ShellFile],
|
||||||
|
['.sh', ShellFile],
|
||||||
['.ts', TypeScriptFile],
|
['.ts', TypeScriptFile],
|
||||||
['.tsx', TypeScriptFile],
|
['.tsx', TypeScriptFile],
|
||||||
]);
|
]);
|
||||||
|
@ -6,6 +6,7 @@ export enum HighlightType {
|
|||||||
Match,
|
Match,
|
||||||
String,
|
String,
|
||||||
SingleLineComment,
|
SingleLineComment,
|
||||||
|
MultiLineComment,
|
||||||
Keyword1,
|
Keyword1,
|
||||||
Keyword2,
|
Keyword2,
|
||||||
}
|
}
|
||||||
@ -19,10 +20,11 @@ export function highlightToColor(type: HighlightType): string {
|
|||||||
return Ansi.color256(21);
|
return Ansi.color256(21);
|
||||||
|
|
||||||
case HighlightType.String:
|
case HighlightType.String:
|
||||||
return Ansi.color256(201);
|
return Ansi.color256(45);
|
||||||
|
|
||||||
case HighlightType.SingleLineComment:
|
case HighlightType.SingleLineComment:
|
||||||
return Ansi.color256(45);
|
case HighlightType.MultiLineComment:
|
||||||
|
return Ansi.color256(201);
|
||||||
|
|
||||||
case HighlightType.Keyword1:
|
case HighlightType.Keyword1:
|
||||||
return Ansi.color256(226);
|
return Ansi.color256(226);
|
||||||
|
Loading…
Reference in New Issue
Block a user