var tabBarOffset int
+// A Tab holds an array of views and a splitTree to determine how the
+// views should be arranged
type Tab struct {
// This contains all the views in this tab
// There is generally only one view per tab, but you can have
// multiple views with splits
- views []*View
+ Views []*View
// This is the current view for this tab
CurView int
// NewTabFromView creates a new tab and puts the given view in the tab
func NewTabFromView(v *View) *Tab {
t := new(Tab)
- t.views = append(t.views, v)
- t.views[0].Num = 0
+ t.Views = append(t.Views, v)
+ t.Views[0].Num = 0
t.tree = new(SplitTree)
t.tree.kind = VerticalSplit
- t.tree.children = []Node{NewLeafNode(t.views[0], t.tree)}
+ t.tree.children = []Node{NewLeafNode(t.Views[0], t.tree)}
w, h := screen.Size()
t.tree.width = w
if globalSettings["infobar"].(bool) {
t.tree.height--
}
+ if globalSettings["keymenu"].(bool) {
+ t.tree.height -= 2
+ }
t.Resize()
// SetNum sets all this tab's views to have the correct tab number
func (t *Tab) SetNum(num int) {
t.tree.tabNum = num
- for _, v := range t.views {
+ for _, v := range t.Views {
v.TabNum = num
}
}
+// Cleanup cleans up the tree (for example if views have closed)
func (t *Tab) Cleanup() {
t.tree.Cleanup()
}
+// Resize handles a resize event from the terminal and resizes
+// all child views correctly
func (t *Tab) Resize() {
w, h := screen.Size()
t.tree.width = w
if globalSettings["infobar"].(bool) {
t.tree.height--
}
+ if globalSettings["keymenu"].(bool) {
+ t.tree.height -= 2
+ }
t.tree.ResizeSplits()
- for i, v := range t.views {
+ for i, v := range t.Views {
v.Num = i
+ if v.Type == vtTerm {
+ v.term.Resize(v.Width, v.Height)
+ }
}
}
// CurView returns the current view
func CurView() *View {
curTab := tabs[curTab]
- return curTab.views[curTab.CurView]
+ return curTab.Views[curTab.CurView]
}
// TabbarString returns the string that should be displayed in the tabbar
} else {
str += " "
}
- str += t.views[t.CurView].Buf.GetName()
+ buf := t.Views[t.CurView].Buf
+ str += buf.GetName()
+ if buf.Modified() {
+ str += " +"
+ }
if i == curTab {
str += "]"
} else {
str += " "
}
- indicies[len(str)-1] = i + 1
+ indicies[Count(str)-1] = i + 1
str += " "
}
return str, indicies
return false
}
str, indicies := TabbarString()
- if x + tabBarOffset >= len(str) {
+ if x+tabBarOffset >= len(str) {
return false
}
var tabnum int
}
sort.Ints(keys)
for _, k := range keys {
- if x + tabBarOffset <= k {
+ if x+tabBarOffset <= k {
tabnum = indicies[k] - 1
break
}
if tooWide == true {
// first we have to work out where the selected tab is
// out of the total length of the tab bar. this is done
- // by extracting the hit-areas from the indicies map
+ // by extracting the hit-areas from the indicies map
// that was constructed by `TabbarString()`
var keys []int
for offset := range indicies {
rightBuffer := currentTabOffset + (centeringOffset / 2)
// check to make sure we haven't overshot the bounds of the string,
- // if we have, then take that remainder and put it on the left side
+ // if we have, then take that remainder and put it on the left side
overshotRight := rightBuffer - len(fileRunes)
if overshotRight > 0 {
leftBuffer = leftBuffer + overshotRight
} else {
rightBuffer = leftBuffer + (w - 2)
}
-
- if rightBuffer > len(fileRunes) - 1 {
+
+ if rightBuffer > len(fileRunes)-1 {
rightBuffer = len(fileRunes) - 1
}
- // construct a new buffer of text to put the
+ // construct a new buffer of text to put the
// newly formatted tab bar text into.
var displayText []rune
}
// if there is more text to the right of the right-most
// column in the tab bar text, then indicate there are more
- // tabs to ther right by displaying a "+"
- if rightBuffer < len(fileRunes) - 1 {
+ // tabs to the right by displaying a "+"
+ if rightBuffer < len(fileRunes)-1 {
displayText = append(displayText, '+')
}
// now store the offset from zero of the left-most text
- // that is being displayed. This is to ensure that when
+ // that is being displayed. This is to ensure that when
// clicking on the tab bar, the correct tab gets selected.
tabBarOffset = leftBuffer
// use the constructed buffer as the display buffer to print
// onscreen.
fileRunes = displayText
+ } else {
+ tabBarOffset = 0
}
// iterate over the width of the terminal display and for each column,
- // write a character into the tab display area with the appropraite style.
+ // write a character into the tab display area with the appropriate style.
for x := 0; x < w; x++ {
if x < len(fileRunes) {
screen.SetContent(x, 0, fileRunes[x], nil, tabBarStyle)