summary refs log tree commit diff stats
path: root/ranger.py
Commit message (Collapse)AuthorAgeFilesLines
* ranger.py: reverted cd-after-exit to the old wayhut2010-02-141-10/+1
| | | | | | | | This breaks cd-after-exit after Ctrl+C again, but enables compatibility with zsh which I prefer over the former. If you only use bash, you can safely revert this commit unless future changes make it break.
* ranger.py: more simple '--debug' flag checkhut2010-02-141-1/+1
|
* ranger.py: improved handling of bad importhut2010-01-261-1/+2
|
* ranger.py: more fixeshut2010-01-121-2/+2
|
* ranger.py: cleanup/fixhut2010-01-111-9/+8
|
* fixed #31, cd-after-exit works even after pressing ^Chut2010-01-111-1/+12
|
* added license informationhut2010-01-081-3/+17
|
* F1 key (inside console) for viewing information about the commandhut2009-12-291-1/+1
|
* shorten comment in ranger.pyhut2009-12-261-11/+5
|
* implemented OpenConsolehut2009-12-251-2/+2
|
* random updateshut2009-12-251-3/+16
|
* tons of stuffhut2009-12-171-1/+1
|
* merged main with __init__hut2009-12-121-1/+1
|
* restructurationshut2009-12-111-2/+4
|
* changing implementation of optionshut2009-12-061-3/+6
|
* structural improvementshut2009-12-011-46/+9
|
* random improvementshut2009-11-291-2/+2
|
* implemented colorschemes.hut2009-11-291-10/+10
|
* started to implement colorschemeshut2009-11-291-6/+11
|
* restructurationhut2009-11-281-33/+33
|
* embedded wrapper.sh into ranger.pyhut2009-11-271-0/+12
|
* cd-after-exithut2009-11-271-4/+17
|
* general improvementhut2009-11-271-1/+1
|
* more VROOMhut2009-11-271-0/+38
v>



                                                           

                                          







                                                                                  

                                          


                                                
                    











                                                                                              
                                                                 


                   
package widgets

import (
	"time"

	"github.com/gdamore/tcell"

	"git.sr.ht/~sircmpwn/aerc2/lib/ui"
)

type StatusLine struct {
	stack    []*StatusMessage
	fallback StatusMessage

	onInvalidate func(d ui.Drawable)
}

type StatusMessage struct {
	bg      tcell.Color
	fg      tcell.Color
	message string
}

func NewStatusLine() *StatusLine {
	return &StatusLine{
		fallback: StatusMessage{
			bg:      tcell.ColorWhite,
			fg:      tcell.ColorBlack,
			message: "Idle",
		},
	}
}

func (status *StatusLine) OnInvalidate(onInvalidate func(d ui.Drawable)) {
	status.onInvalidate = onInvalidate
}

func (status *StatusLine) Invalidate() {
	if status.onInvalidate != nil {
		status.onInvalidate(status)
	}
}

func (status *StatusLine) Draw(ctx *ui.Context) {
	line := &status.fallback
	if len(status.stack) != 0 {
		line = status.stack[len(status.stack)-1]
	}
	style := tcell.StyleDefault.Background(line.bg).Foreground(line.fg)
	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
	ctx.Printf(0, 0, style, "%s", line.message)
}

func (status *StatusLine) Set(text string) *StatusMessage {
	status.fallback = StatusMessage{
		bg:      tcell.ColorWhite,
		fg:      tcell.ColorBlack,
		message: text,
	}
	status.Invalidate()
	return &status.fallback
}

func (status *StatusLine) Push(text string, expiry time.Duration) *StatusMessage {
	msg := &StatusMessage{
		bg:      tcell.ColorWhite,
		fg:      tcell.ColorBlack,
		message: text,
	}
	status.stack = append(status.stack, msg)
	go (func() {
		time.Sleep(expiry)
		for i, m := range status.stack {
			if m == msg {
				status.stack = append(status.stack[:i], status.stack[i+1:]...)
				break
			}
		}
		status.Invalidate()
	})()
	return msg
}

func (msg *StatusMessage) Color(bg tcell.Color, fg tcell.Color) {
	msg.bg = bg
	msg.fg = fg
}