-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
200 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package textinput | ||
|
||
import ( | ||
"image/color" | ||
"time" | ||
|
||
tea "github.com/charmbracelet/bubbletea/v2" | ||
"github.com/charmbracelet/lipgloss/v2" | ||
) | ||
|
||
// DefaultStyles returns the default styles for focused and blurred states for | ||
// the textarea. | ||
func DefaultStyles(isDark bool) Styles { | ||
lightDark := lipgloss.LightDark(isDark) | ||
|
||
var s Styles | ||
s.Focused = StyleState{ | ||
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")), | ||
Suggestion: lipgloss.NewStyle().Foreground(lipgloss.Color("240")), | ||
Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")), | ||
Text: lipgloss.NewStyle(), | ||
} | ||
s.Blurred = StyleState{ | ||
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")), | ||
Suggestion: lipgloss.NewStyle().Foreground(lipgloss.Color("240")), | ||
Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")), | ||
Text: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("245"), lipgloss.Color("7"))), | ||
} | ||
s.Cursor = CursorStyle{ | ||
Color: lipgloss.Color("7"), | ||
Shape: tea.CursorBlock, | ||
Blink: true, | ||
} | ||
return s | ||
} | ||
|
||
// DefaultLightStyles returns the default styles for a light background. | ||
func DefaultLightStyles() Styles { | ||
return DefaultStyles(false) | ||
} | ||
|
||
// DefaultDarkStyles returns the default styles for a dark background. | ||
func DefaultDarkStyles() Styles { | ||
return DefaultStyles(true) | ||
} | ||
|
||
// Styles are the styles for the textarea, separated into focused and blurred | ||
// states. The appropriate styles will be chosen based on the focus state of | ||
// the textarea. | ||
type Styles struct { | ||
Focused StyleState | ||
Blurred StyleState | ||
Cursor CursorStyle | ||
} | ||
|
||
// StyleState that will be applied to the text area. | ||
// | ||
// StyleState can be applied to focused and unfocused states to change the styles | ||
// depending on the focus state. | ||
// | ||
// For an introduction to styling with Lip Gloss see: | ||
// https://github.com/charmbracelet/lipgloss | ||
type StyleState struct { | ||
Text lipgloss.Style | ||
Placeholder lipgloss.Style | ||
Suggestion lipgloss.Style | ||
Prompt lipgloss.Style | ||
} | ||
|
||
// CursorStyle is the style for real and virtual cursors. | ||
type CursorStyle struct { | ||
// Style styles the cursor block. | ||
// | ||
// For real cursors, the foreground color set here will be used as the | ||
// cursor color. | ||
Color color.Color | ||
|
||
// Shape is the cursor shape. The following shapes are available: | ||
// | ||
// - tea.CursorBlock | ||
// - tea.CursorUnderline | ||
// - tea.CursorBar | ||
// | ||
// This is only used for real cursors. | ||
Shape tea.CursorShape | ||
|
||
// CursorBlink determines whether or not the cursor should blink. | ||
Blink bool | ||
|
||
// BlinkSpeed is the speed at which the virtual cursor blinks. This has no | ||
// effect on real cursors as well as no effect if the cursor is set not to | ||
// [CursorBlink]. | ||
// | ||
// By default, the blink speed is set to about 500ms. | ||
BlinkSpeed time.Duration | ||
} |
Oops, something went wrong.