1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-12-04 14:46:29 -05:00

🔀 Merge branch 'master' into feeds

This commit is contained in:
makeworld 2020-09-04 20:45:07 -04:00
commit 0156769591
9 changed files with 102 additions and 15 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
# Binaries
amfora
amfora.exe
amfora-*
build
dist

View File

@ -7,16 +7,24 @@ go:
- "1.14"
- "1.15"
os:
- linux
- osx
- windows
before_install:
- if [ "$TRAVIS_OS_NAME" = "windows" ]; then choco install make; fi
script:
- go test ./...
- go build
- go test -race ./...
- make
env:
GO111MODULE=on
cache:
directories:
- $HOME/.cache/go-build
- $GOCACHE
- $GOPATH/pkg/mod
# TODO: GitHub Releases deploy

View File

@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- `ansi` config setting, to disable ANSI colors in pages (#79, #86)
### Changed
- Disabling the `color` config setting also disables ANSI colors in pages (#79, #86)
## [v1.5.0] - 2020-09-01

54
Makefile Normal file
View File

@ -0,0 +1,54 @@
GIT_EXISTS := $(shell git status > /dev/null 2>&1 ; echo $$?)
ifeq ($(GIT_EXISTS), 0)
ifeq ($(shell git tag --points-at HEAD),)
# Not currently on a tag
VERSION := $(shell git describe --tags | sed 's/-.*/-next/') # v1.2.3-next
else
# On a tag
VERSION := $(shell git tag --points-at HEAD)
endif
COMMIT := $(shell git rev-parse --verify HEAD)
endif
INSTALL := install -o root -g 0
INSTALL_DIR := /usr/local/bin
DESKTOP_DIR := /usr/share/applications
.PHONY: all build install desktop clean uninstall fmt
all: build
build:
ifneq ($(GIT_EXISTS), 0)
# No Git repo
$(error No Git repo was found, which is needed to compile the commit and version)
endif
@echo "Downloading dependencies"
@go env -w GO111MODULE=on ; go mod download
@echo "Building binary"
@go env -w GO111MODULE=on CGO_ENABLED=0 ; go build -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.builtBy=Makefile"
install:
@echo "Installing Amfora to $(INSTALL_DIR)"
@$(INSTALL) -m 755 amfora $(INSTALL_DIR)
desktop:
@echo "Setting up desktop file"
@$(INSTALL) -m 644 amfora.desktop $(DESKTOP_DIR)
@update-desktop-database $(DESKTOP_DIR)
clean:
@echo "Removing Amfora binary in local directory"
@$(RM) amfora
uninstall:
@echo "Removing Amfora from $(INSTALL_DIR)"
@$(RM) $(INSTALL_DIR)/amfora
@echo "Removing desktop file"
-@$(RM) $(DESKTOP_DIR)/amfora.desktop
-@update-desktop-database $(DESKTOP_DIR)
fmt:
go fmt ./...

View File

@ -27,7 +27,7 @@ It fully passes Sean Conman's client torture test, including the new Unicode tes
### Binary
Download a binary from the [releases](https://github.com/makeworld-the-better-one/amfora/releases) page. On Unix-based systems you might have to make the file executable with `chmod +x <filename>`. You should also move the binary to `/usr/local/bin/`.
Download a binary from the [releases](https://github.com/makeworld-the-better-one/amfora/releases) page. On Unix-based systems you might have to make the file executable with `chmod +x <filename>`. You can rename the file to just `amfora` for easy access, and move it to `/usr/local/bin/`.
On Windows, make sure you click "Advanced > Run anyway" after double-clicking, or something like that.
@ -59,17 +59,20 @@ brew upgrade amfora
### From Source
This section is for programmers who want to install from source. Make sure you're using Go 1.13 at least, as earlier versions will fail to build.
Install latest release:
```
go env -w GO111MODULE=on
go get github.com/makeworld-the-better-one/amfora
The recommended way of installing Amfora fom source is using the Makefile. Note that this requires GNU Make, so use the `gmake` (not `make`) command on macOS. You may have to install it with `brew install make`. On Windows, you can install [Chocolatey](https://chocolatey.org/install) and run `choco install make`.
Note that the Makefile currently assumes that git is available, and that it is inside a git repository.
```shell
git clone https://github.com/makeworld-the-better-one/amfora
cd amfora
# git checkout v1.2.3 # Optionally pin to a specific version instead of the latest commit
make
sudo make install # Not for Windows!
sudo make desktop # Optional, installs .desktop file. Not for Windows or macOS
```
Install latest commit:
```
go env -w GO111MODULE=on
go get github.com/makeworld-the-better-one/amfora@master
```
Because you installed with the Makefile, running `amfora -v` will tell you exactly what commit the binary was built from.
## Usage

View File

@ -236,6 +236,7 @@ func Init() error {
viper.SetDefault("a-general.http", "default")
viper.SetDefault("a-general.search", "gus.guru/search")
viper.SetDefault("a-general.color", true)
viper.SetDefault("a-general.ansi", true)
viper.SetDefault("a-general.bullets", true)
viper.SetDefault("a-general.left_margin", 0.15)
viper.SetDefault("a-general.max_width", 100)

View File

@ -33,6 +33,9 @@ search = "gemini://gus.guru/search"
# Whether colors will be used in the terminal
color = true
# Whether ANSI codes from the page content should be rendered
ansi = true
# Whether to replace list asterisks with unicode bullets
bullets = true

View File

@ -30,6 +30,9 @@ search = "gemini://gus.guru/search"
# Whether colors will be used in the terminal
color = true
# Whether ANSI codes from the page content should be rendered
ansi = true
# Whether to replace list asterisks with unicode bullets
bullets = true

View File

@ -7,6 +7,7 @@ package renderer
import (
"fmt"
urlPkg "net/url"
"regexp"
"strconv"
"strings"
@ -15,12 +16,17 @@ import (
"gitlab.com/tslocum/cview"
)
// Regex for identifying ANSI color codes
var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`)
// RenderANSI renders plain text pages containing ANSI codes.
// Practically, it is used for the text/x-ansi.
func RenderANSI(s string, leftMargin int) string {
s = cview.Escape(s)
if viper.GetBool("a-general.color") {
if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") {
s = cview.TranslateANSI(s)
} else {
s = ansiRegex.ReplaceAllString(s, "")
}
var shifted string
lines := strings.Split(s, "\n")
@ -277,9 +283,12 @@ func convertRegularGemini(s string, numLinks, width int, proxied bool) (string,
// If it's not a gemini:// page, set this to true.
func RenderGemini(s string, width, leftMargin int, proxied bool) (string, []string) {
s = cview.Escape(s)
if viper.GetBool("a-general.color") {
if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") {
s = cview.TranslateANSI(s)
} else {
s = ansiRegex.ReplaceAllString(s, "")
}
lines := strings.Split(s, "\n")
links := make([]string, 0)