Skip to content

Commit

Permalink
Add support for ligatures, cursor shapes (and images) (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
liamg authored Aug 2, 2021
1 parent c18b702 commit 765a781
Show file tree
Hide file tree
Showing 26 changed files with 784 additions and 387 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
.vscode
/darktile
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ Darktile is a GPU rendered terminal emulator designed for tiling window managers

- GPU rendering
- Unicode support
- Variety of themes available (or build your own!)
- Compiled-in powerline font
- Configurable/customisable, supports custom themes, fonts etc.
- Hints: Context-aware overlays e.g. hex colour viewer
- Works with your favourite monospaced TTF/OTF fonts
- Font ligatures (turn it off if you're not a ligature fan)
- Hints: Context-aware overlays e.g. hex colour viewer, octal permission annotation
- Take screenshots with a single key-binding
- Sixel support
- Transparency
- Sixels
- Window transparency (0-100%)
- Customisable cursor (most popular image formats supported)

<p align="center">
<img src="cursor.gif">
</p>

## Installation

Expand Down Expand Up @@ -43,11 +50,14 @@ Darktile will use sensible defaults if no config/theme files are available. The
Found in the config directory (see above) inside `config.yaml`.

```yaml
opacity: 1.0 # window opacity: 0.0 is fully transparent, 1.0 is fully opaque
opacity: 1.0 # Window opacity: 0.0 is fully transparent, 1.0 is fully opaque
font:
family: "" # Find possible values for this by running 'darktile list-fonts'
size: 16
dpi: 72
family: "" # Font family. Find possible values for this by running 'darktile list-fonts'
size: 16 # Font size
dpi: 72 # DPI
ligatures: true # Enable font ligatures e.g. render '≡' instead of '==='
cursor:
image: "" # Path to an image to render as your cursor (defaults to standard rectangular cursor)
```
### Example Theme
Expand Down
Binary file added cursor.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions internal/app/darktile/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"errors"
"fmt"
"image"
"os"
"time"

Expand Down Expand Up @@ -48,6 +49,8 @@ var rootCmd = &cobra.Command{
if _, err := conf.Save(); err != nil {
return fmt.Errorf("failed to write config file: %w", err)
}
fmt.Println("Config written.")
return nil
}

var theme *termutil.Theme
Expand Down Expand Up @@ -91,6 +94,16 @@ var rootCmd = &cobra.Command{
gui.WithFontSize(conf.Font.Size),
gui.WithFontFamily(conf.Font.Family),
gui.WithOpacity(conf.Opacity),
gui.WithLigatures(conf.Font.Ligatures),
}

if conf.Cursor.Image != "" {
img, err := getImageFromFilePath(conf.Cursor.Image)
if err != nil {
startupErrors = append(startupErrors, err)
} else {
options = append(options, gui.WithCursorImage(img))
}
}

if screenshotAfterMS > 0 {
Expand Down Expand Up @@ -118,6 +131,16 @@ var rootCmd = &cobra.Command{
},
}

func getImageFromFilePath(filePath string) (image.Image, error) {
f, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer f.Close()
image, _, err := image.Decode(f)
return image, err
}

func Execute() error {
rootCmd.Flags().BoolVar(&showVersion, "version", showVersion, "Show darktile version information and exit")
rootCmd.Flags().BoolVar(&rewriteConfig, "rewrite-config", rewriteConfig, "Write the resultant config after parsing config files and merging with defauls back to the config file")
Expand Down
12 changes: 9 additions & 3 deletions internal/app/darktile/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import (
type Config struct {
Opacity float64
Font Font
Cursor Cursor
}

type Font struct {
Family string
Size float64
DPI float64
Family string
Size float64
DPI float64
Ligatures bool
}

type Cursor struct {
Image string
}

type ErrorFileNotFound struct {
Expand Down
7 changes: 4 additions & 3 deletions internal/app/darktile/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
var defaultConfig = Config{
Opacity: 1.0,
Font: Font{
Family: "", // internally packed font will be loaded by default
Size: 18.0,
DPI: 72.0,
Family: "", // internally packed font will be loaded by default
Size: 18.0,
DPI: 72.0,
Ligatures: true,
},
}

Expand Down
Loading

0 comments on commit 765a781

Please sign in to comment.