chore: offload user input to InputManager
This commit is contained in:
40
src/shell/wush/Environment.ts
Normal file
40
src/shell/wush/Environment.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Wush environment manager
|
||||
* Manages environment variables, aliases etc.
|
||||
*/
|
||||
export class Environment {
|
||||
private variables: Record<string, string> = {}
|
||||
private aliases: Record<string, string> = {}
|
||||
|
||||
SetVariable(name: string, value: string | null): void {
|
||||
if (value === null) {
|
||||
// remove the variable if value is null
|
||||
delete this.variables[name]
|
||||
} else this.variables[name] = value
|
||||
}
|
||||
|
||||
GetVariable(name: string): string | null {
|
||||
return this.variables[name] ?? null
|
||||
}
|
||||
|
||||
SetAlias(name: string, value: string | null): void {
|
||||
if (value === null) {
|
||||
// remove the alias if value is null
|
||||
delete this.aliases[name]
|
||||
} else this.aliases[name] = value
|
||||
}
|
||||
|
||||
GetAlias(name: string): string | null {
|
||||
return this.aliases[name] ?? null
|
||||
}
|
||||
|
||||
GetAliasesByValue(value: string): string[] | null {
|
||||
const keys: string[] = []
|
||||
|
||||
for (const key in this.aliases)
|
||||
if (this.aliases[key] === value)
|
||||
keys.push(key)
|
||||
|
||||
return keys.length === 0 ? null : keys
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user