/
changePercent.go
86 lines (72 loc) · 2.32 KB
/
changePercent.go
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
/*
Copyright © 2021 Bhargav SNV bhargavsnv100@gmail.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utilitywidgets
import (
"github.com/Gituser143/cryptgo/pkg/widgets"
ui "github.com/gizak/termui/v3"
)
var durationRows = [][]string{{"1 Hour"}, {"24 Hours"}, {"7 Days"}, {"14 Days"}, {"30 Days"}, {"200 Days"}, {"1 Year"}}
// DurationMap maps duration strings to the format required by coinGecko API
var DurationMap = map[string]string{
"1 Hour": "1h",
"24 Hours": "24h",
"7 Days": "7d",
"14 Days": "14d",
"30 Days": "30d",
"200 Days": "200d",
"1 Year": "1y",
}
// ChangePercentageDurationTable holds a table which helps change percentage duration values
type ChangePercentageDurationTable struct {
*widgets.Table
}
// NewChangePercentPage creates, initialises and returns a pointer to
// an instance of CurrencyTable
func NewChangePercentPage() *ChangePercentageDurationTable {
c := &ChangePercentageDurationTable{
Table: widgets.NewTable(),
}
c.Table.Title = " Select Duration for Percentage Change "
c.Table.Header = []string{"Duration"}
c.Table.Rows = durationRows
c.Table.CursorColor = ui.ColorCyan
c.Table.ShowCursor = true
c.Table.ColWidths = []int{5}
c.Table.ColResizer = func() {
x := c.Table.Inner.Dx()
c.Table.ColWidths = []int{
x,
}
}
return c
}
// Resize helps rresize the ChangePercentageDurationTable according to terminal dimensions
func (c *ChangePercentageDurationTable) Resize(termWidth, termHeight int) {
textWidth := 50
textHeight := len(c.Table.Rows) + 3
x := (termWidth - textWidth) / 2
y := (termHeight - textHeight) / 2
if x < 0 {
x = 0
textWidth = termWidth
}
if y < 0 {
y = 0
textHeight = termHeight
}
c.Table.SetRect(x, y, textWidth+x, textHeight+y)
}
// Draw puts the required text into the widget
func (c *ChangePercentageDurationTable) Draw(buf *ui.Buffer) {
c.Table.Draw(buf)
}