Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] buffer clipboard support #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
app.win.ClickBuffer(app.win.HorizontalBufferOffset(x))
} else if x > w-app.win.MemberWidth() {
app.win.ClickMember(y + app.win.MemberOffset())
} else {
app.win.StartCopy(y, x - app.win.ChannelWidth())
}
}
if ev.Buttons() == 0 {
Expand Down Expand Up @@ -515,6 +517,8 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
}
}
}
} else {
app.win.EndCopy(y, x - app.win.ChannelWidth())
}
app.win.ClickBuffer(-1)
app.win.ClickMember(-1)
Expand Down
31 changes: 26 additions & 5 deletions ui/buffers.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ type buffer struct {

scrollAmt int
isAtTop bool

copyStart *CopyStart
}

type BufferList struct {
Expand Down Expand Up @@ -375,15 +377,19 @@ func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line)

n := len(b.lines)
line.At = line.At.UTC()
copyOffset := 0

if !line.Mergeable && current.openedOnce {
line.Body = line.Body.ParseURLs()
}

if line.Mergeable && n != 0 && b.lines[n-1].Mergeable {
l := &b.lines[n-1]
splitLines := len(l.newLines)
if !bs.mergeLine(l, line) {
b.lines = b.lines[:n-1]
} else {
copyOffset = len(l.newLines) - splitLines
}
// TODO change b.scrollAmt if it's not 0 and bs.current is idx.
} else {
Expand All @@ -392,6 +398,12 @@ func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line)
if b == current && 0 < b.scrollAmt {
b.scrollAmt += len(line.NewLines(bs.textWidth)) + 1
}
copyOffset = 1 + len(line.newLines)
}

if b.copyStart != nil {
/* Update copy indicator */
b.copyStart.y -= copyOffset
}

if notify != NotifyNone && b != current {
Expand Down Expand Up @@ -780,8 +792,12 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int

if yi >= y0 {
identSt := tcell.StyleDefault.
Foreground(line.HeadColor).
Reverse(line.Highlight)
Foreground(line.HeadColor)
if b.WantsCopyIndicator(0, yi, true) {
identSt = identSt.Reverse(true)
} else {
identSt = identSt.Reverse(line.Highlight)
}
printIdent(screen, x0+7, yi, nickColWidth, Styled(line.Head, identSt))
}

Expand All @@ -790,12 +806,12 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
style := tcell.StyleDefault
nextStyles := line.Body.styles

for i, r := range line.Body.string {
if 0 < len(nextStyles) && nextStyles[0].Start == i {
for j, r := range line.Body.string {
if 0 < len(nextStyles) && nextStyles[0].Start == j {
style = nextStyles[0].Style
nextStyles = nextStyles[1:]
}
if 0 < len(nls) && i == nls[0] {
if 0 < len(nls) && j == nls[0] {
x = x1
y++
nls = nls[1:]
Expand All @@ -809,6 +825,11 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
}

if y >= y0 {
if b.WantsCopyIndicator(x - x1, y, false) {
style = style.Reverse(true)
} else {
style = style.Reverse(false)
}
screen.SetContent(x, y, r, nil, style)
}
x += runeWidth(r)
Expand Down
Loading