-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
75 lines (69 loc) · 2.39 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { formatText } from './lib/style'
import { ResumeHelper } from './lib/resume-helper'
// hack to get jquery working
import jquery from 'jquery'
import terminal from 'jquery.terminal'
import { SectionCommands, Format, Greetings } from './config'
const $ = terminal(jquery, this)
const resumeHelper = new ResumeHelper()
const promptTimeFormatOptions = { hour12: false }
$(document).ready(function () {
const defaultCommands: any = {
help: function () {
this.echo(formatText('bold', 'Terminal Resumé'))
this.echo('Available commands:')
SectionCommands.forEach(command => {
this.echo(' ' + formatText('bold', command.name) + ': ' + command.helpText)
})
this.echo(' ' + formatText('bold', 'help') + ': this help screen')
// about should always be last
this.echo(' ' + formatText('bold', 'about') + ': about this site\n')
},
about: function () {
this.echo('This website is made with terminal-resume.\n')
}
}
const sectionCommands: any = {}
// dynamically populate sectionCommands from config
SectionCommands.forEach(command => {
sectionCommands[command.name] = function () {
let str = ''
command.sections.forEach(section => {
const content = resumeHelper.getSection(section)
if (content.trimEnd() !== '') {
str += Format.SectionStart
str += content
str += Format.SectionEnd
}
})
this.echo(str)
}
})
const customCommands: any = {
// insert your custom commands here
// see https://github.com/jcubic/jquery.terminal/wiki/Getting-Started#creating-the-interpreter
// for examples on how to use jquery-terminal
// terminal-resume uses the object intepreter
example: function () {
this.echo('This is an example command.\n')
}
}
$('#term').terminal(
{ ...defaultCommands, ...sectionCommands, ...customCommands },
{
greetings: Greetings +
'Welcome to Terminal Resumé! Type ' +
formatText('green', 'help') + ' to start.\n',
prompt: function (p: (arg0: string) => void) {
const time = new Date().toLocaleTimeString([], promptTimeFormatOptions)
p(formatText('orange', `➜ ${time} guest@resumé ~> `))
},
onBlur: function () {
// prevent losing focus
return false
},
checkArity: false,
completion: true,
history: true
})
})