This repository was archived by the owner on Jan 23, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlayout.js
More file actions
102 lines (82 loc) · 2.3 KB
/
Copy pathlayout.js
File metadata and controls
102 lines (82 loc) · 2.3 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const blit = require('txt-blit')
const util = require('./util')
const chalk = require('chalk')
const gradient = require('gradient-string')
const camelCase = require('camelcase')
class Layout {
constructor (rc) {
this._rc = rc
this._opts = rc.layout
}
render (state) {
const screen = []
const width = process.stdout.columns
const height = process.stdout.rows
const maxPageHeight = this.maxPageHeight()
const page = state.currentPage()
const pageText = page.render(state, width, maxPageHeight)
if (this.titleVisible()) {
blit(screen, this.titleBar(state), 0, 0)
blit(screen, pageText, 0, 1)
} else {
blit(screen, pageText, 0, 0)
}
if (this.statusVisible()) {
blit(screen, this.statusBar(state), 0, height - 2)
}
blit(screen, this.prompt(state), 0, height - 1)
return screen.join('\n')
}
titleBar (state) {
let text = 'Delta Chat'
const opts = this._opts.titlebar
if (opts.gradient) {
text = (gradient[opts.gradient] || gradient.fruit)(text)
} else if (opts.textColor) {
text = (chalk[opts.textColor] || chalk.white)(text)
}
if (opts.align === 'center') {
text = util.centerText(text, process.stdout.columns)
}
if (opts.bold === true) {
text = chalk.bold(text)
}
text = bgColor(opts.bgColor)(text)
return [ text ]
}
statusBar (state) {
const date = chalk.yellow(util.dateTime())
const email = this._rc.email
const name = chalk.yellow(email.split('@')[0])
const text = [ `[${date}]`, `[${name}]` ].join(' ')
return [
bgColor(this._opts.statusbar.bgColor)(
util.leftAlignText(chalk.white(text), process.stdout.columns)
)
]
}
prompt (state) {
const index = state.currentPageIndex() + 1
const name = state.currentPage().name()
return [
`[${index}:${name}] ${state.input.line()}`
]
}
maxPageHeight () {
let height = process.stdout.rows - 1
if (this.titleVisible()) height--
if (this.statusVisible()) height--
return height
}
titleVisible () {
return this._opts.titlebar.show === true
}
statusVisible () {
return this._opts.statusbar.show === true
}
}
function bgColor (color) {
color = color || 'blue'
return chalk[camelCase(`bg-${color}`)]
}
module.exports = Layout