-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Flow-Works/thinliquid/qol
✨ feature: better git and theme support
- Loading branch information
Showing
5 changed files
with
181 additions
and
50 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,45 +5,86 @@ import 'https://cdn.jsdelivr.net/npm/[email protected]/lib/xterm.min.js'; | |
|
||
import FitAddon from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'; | ||
import WebLinksAddon from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'; | ||
import CanvasAddon from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'; | ||
import FontFaceObserver from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'; | ||
|
||
import { loadCSS } from '/scripts/utilities.js'; | ||
import { config } from '/scripts/managers.js'; | ||
|
||
import { CommandsAddon } from './terminal/handler.js'; | ||
|
||
import { _auth } from '../../../scripts/firebase.js'; | ||
import * as auth from 'https://www.gstatic.com/firebasejs/10.0.0/firebase-auth.js'; | ||
|
||
const commands = { | ||
'cd': './terminal/commands/cd.js' | ||
cd: './terminal/commands/cd.js', | ||
}; | ||
|
||
const term = new Terminal({ | ||
cursorBlink: true, | ||
fontFamily: 'JetBrains Mono Nerd Font, monospace', | ||
letterSpacing: '1', | ||
allowTransparency: true | ||
}); | ||
|
||
auth.onAuthStateChanged(_auth, (user) => { | ||
if (user) { | ||
let dir = { | ||
path: '/', | ||
set: (str) => { | ||
dir.path = str; | ||
} | ||
}; | ||
window.loadCSS = (FILE_URL, callback) => { | ||
const styleEle = document.createElement('link'); | ||
|
||
let username; | ||
if (_auth.currentUser.displayName !== null) username = _auth.currentUser.displayName.toLowerCase().replaceAll(' ', '-'); | ||
else username = 'guest'; | ||
const usr = { username }; | ||
styleEle.setAttribute('rel', 'stylesheet'); | ||
styleEle.setAttribute('type', 'text/css'); | ||
styleEle.setAttribute('href', FILE_URL); | ||
|
||
document.head.appendChild(styleEle); | ||
|
||
const fitAddon = new FitAddon.FitAddon(); | ||
styleEle.addEventListener('load', () => { | ||
if (typeof callback == 'function') | ||
callback(); | ||
|
||
term.loadAddon(fitAddon); | ||
term.loadAddon(new WebLinksAddon.WebLinksAddon()); | ||
term.loadAddon(new CommandsAddon({ commands }, usr, dir)); | ||
}); | ||
}; | ||
|
||
window.addEventListener('load', () => { | ||
window.loadCSS(config.settings.get('theme').url, () => { | ||
const term = new Terminal({ | ||
cursorBlink: true, | ||
fontFamily: 'JetBrains Mono Nerd Font, monospace', | ||
fontSize: '15', | ||
lineHeight: '1.1', | ||
letterSpacing: '1.4', | ||
allowTransparency: true, | ||
theme: { | ||
background: getComputedStyle(document.querySelector(':root')).getPropertyValue('--desktop-bg'), | ||
foreground: getComputedStyle(document.querySelector(':root')).getPropertyValue('--text-color'), | ||
} | ||
}); | ||
|
||
term.open(document.getElementById('terminal')); | ||
fitAddon.fit(); | ||
} | ||
auth.onAuthStateChanged(_auth, (user) => { | ||
if (user) { | ||
let dir = { | ||
path: '/', | ||
set: (str) => { | ||
dir.path = str; | ||
}, | ||
}; | ||
|
||
let username; | ||
if (_auth.currentUser.displayName !== null) | ||
username = _auth.currentUser.displayName | ||
.toLowerCase() | ||
.replaceAll(' ', '-'); | ||
else username = 'guest'; | ||
|
||
const usr = { username }; | ||
|
||
const fitAddon = new FitAddon.FitAddon(); | ||
|
||
term.loadAddon(fitAddon); | ||
term.loadAddon(new WebLinksAddon.WebLinksAddon()); | ||
term.loadAddon(new CanvasAddon.CanvasAddon()); | ||
term.loadAddon(new CommandsAddon({ commands }, usr, dir)); | ||
|
||
const font = new FontFaceObserver('JetBrains Mono Nerd Font'); | ||
font.load().then(() => { | ||
term.open(document.getElementById('terminal')); | ||
}, () => { | ||
window.location.reload(); | ||
}); | ||
|
||
fitAddon.fit(); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,13 @@ import sh from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'; | |
export class CommandsAddon { | ||
_disposables = []; | ||
|
||
promptMSG = async () => `${c.blue('')}${c.bgBlue(` flow@${this.user.username}`)}${c.bgCyan(c.blue('') + ` ${this.dir.path}`)}${c.cyan('')} `; | ||
promptMSG = async () => { | ||
if (await this.fs.readdirSync(this.dir.path).includes('.git')) { | ||
return `${c.green('')}${c.bgGreen(` flow@${this.user.username}`)}${c.bgCyan(c.green('') + ` ${this.fs.realpathSync(this.dir.path)}`)}${c.bgBlue(c.cyan(' '))}${c.bgBlue(` ${this.fs.readFileSync(this.dir.path + '/.git/HEAD').toString().replaceAll('\n', '').split('ref: refs/heads/')[1]}`)}${c.blue('')} `; | ||
} else { | ||
return `${c.green('')}${c.bgGreen(` flow@${this.user.username}`)}${c.bgCyan(c.green('') + ` ${this.fs.realpathSync(this.dir.path)}`)}${c.cyan('')} `; | ||
} | ||
}; | ||
|
||
constructor(options, usr, dir) { | ||
this.commandsMap = options.commands; | ||
|
@@ -18,6 +24,11 @@ export class CommandsAddon { | |
this.current = ''; | ||
|
||
BrowserFS.install(window); | ||
} | ||
|
||
activate(term) { | ||
this.terminal = term; | ||
|
||
BrowserFS.configure({ | ||
fs: 'AsyncMirror', | ||
options: { | ||
|
@@ -32,20 +43,15 @@ export class CommandsAddon { | |
if (e) console.error(e); | ||
|
||
this.fs = require('fs'); | ||
this.promptMSG = async () => `${c.blue('')}${c.bgBlue(` flow@${this.user.username}`)}${c.bgCyan(c.blue('') + ` ${this.fs.realpathSync(this.dir.path)}`)}${c.cyan('')} `; | ||
|
||
this.terminal.prompt = async () => { | ||
this.terminal.write('\r' + await this.promptMSG()); | ||
}; | ||
|
||
this.terminal.writeln('Welcome to FluSH!'); | ||
this.terminal.writeln(''); | ||
this.terminal.prompt(); | ||
}); | ||
} | ||
|
||
activate(term) { | ||
this.terminal = term; | ||
|
||
this.terminal.prompt = async () => { | ||
this.terminal.write('\r' + await this.promptMSG()); | ||
}; | ||
|
||
this.terminal.writeln('Welcome to FluSH!'); | ||
this.terminal.writeln(''); | ||
this.terminal.prompt(); | ||
|
||
this.terminal.attachCustomKeyEventHandler(async (key) => { | ||
if (key.code === 'KeyV' && key.ctrlKey && key.type === 'keydown') { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters