Giter Site home page Giter Site logo

lrstanley / bubblezone Goto Github PK

View Code? Open in Web Editor NEW
520.0 4.0 15.0 417 KB

helper utility for BubbleTea, allowing easy mouse event tracking

Home Page: https://pkg.go.dev/github.com/lrstanley/bubblezone

License: MIT License

Makefile 1.34% Go 98.66%
bubbletea cli go tui golang lipgloss terminal

bubblezone's Introduction

header

👋, I'm @lrstanley, and this is my GitHub profile, where I frequently publish my open-source projects. I hope some of them can be beneficial to you or others. If you like any projects, please give some of them a ⭐, it would be much appreciated!

  • 🌎 Originally from Michigan, US, I am currently located in North Carolina, US.
  • 🚀 I am working on many projects, primarily revolving around tools to help improve the experience for other developers.
  • 🔗 Take a look at my personal website, https://liam.sh.
  • 📝 Browse some of the blog posts I have written here.
  • 🙋‍♂️ Want to chat? Check out the Bytecord discord server, we talk programming, technology, 3d printers, games, etc.
  • ❤️ Feeling generous? Sponsor me!
  • 🗝️ Security concern with one of my repositories? Every repo has a SECURITY.md (example).

📌 A note on archived repositories

I have a lot of repositories that have been developed over the years, many of them are related to something I would be working on at the time, and I have transitioned to another tool or similar, or simply there wasn't enough desire from others to allow me to continue working on the projects/keeping it active. As such, I mark repositories as archived to make it obvious that there is a lack of attention being put in place on that project. This does not mean it's abandoned forever. If the need to maintain it resurges or I start working on the project again, I will unarchive it.

bubblezone's People

Contributors

blazingbbq avatar dependabot[bot] avatar lrstanley avatar srlehn avatar thisguycodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bubblezone's Issues

bug: bubblezone filters out CBT CSI sequences

🌧 Describe the problem

The "CSI Pn Z" sequence that is used for marking in this project is an already defined ANSI CSI sequence (CBT). If the input already contains CBT sequences prior to marking, those would be filtered out.

⛅ Expected behavior

CSI sequences have a private subset for use cases like here.

🔄 Minimal reproduction

No response

💠 Version: bubblezone

?

🖥 Version: Operating system

linux/debian

⚙ Additional context

No response

🤝 Requirements

feature: workflow for de-duplicating mouse events when within a given zone

✨ Describe the feature you'd like

A way with BubbleZone to reduce the chance of duplicated clicks being sent.

🌧 Is your feature request related to a problem?

Today, when holding one of the mouse buttons (and dragging), BubbleTea emits multiple events for each cell that the mouse has dragged over. The common way that I think most people use BubbleZone, where it's a simple bounds check, will be subject to situations where a user might intend on clicking something, then causing a drag during the clicking process (this isn't an issue unless they drag over a column/row boundary).


Not sure what the best approach to address this issue. Ideally, if we could capture a mouseup event, that is specific to left or right, I think that would be the ideal situation, rather than mousedown. A mousedown event can be triggered multiple times due to dragging, whereas I don't think mouseup would.

Today, I believe mouseup isn't specific to left/right.

Below screenshot shows an example of drag causing multiple events:


Maybe if the developer does an action based on a zone + mouse event, we have some way of caching that? And if we receive a mouseup event, we clear that cache? This would mean that unless we receive a mouseup event, we could have a way of checking if we've already done an action from mousedown for that zone?

bug: [undefined: atomic.Bool ]

🌧 Describe the problem

When I attend to run the full-lipgloss example, I got the following error message:

github.com/lrstanley/bubblezone

../go/pkg/mod/github.com/lrstanley/[email protected]/manager.go:54:17: undefined: atomic.Bool

⛅ Expected behavior

I expect to run the full test

🔄 Minimal reproduction

1 in my directory full-lipgloss I have the following files:
dialog.go go.mod go.sum history.go list.go main.go tabs.go util.go
2 Then I run go run . and I got the error message

💠 Version: bubblezone

github.com/lrstanley/bubblezone v0.0.0-20221015234447-8db0faca329d h1:cYNT20vgHPsn7fK6cx/zy3iCaPnlcztWDerhx4iPTZ8= github.com/lrstanley/bubblezone v0.0.0-20221015234447-8db0faca329d/go.mod h1:u+P0PRRatV4IhcL0LncRZAew9nlYvTQvgYbEu5h1iw0= g

🖥 Version: Operating system

linux/other

⚙ Additional context

I am running linux debian 11 in a Pixelbook .
go version is go1.18.7 linux/amd64

🤝 Requirements

bug: Console freezes with certain lipgloss.place usage

🌧 Describe the problem

I'm currently using bubbletea and bubblezone to develop a small console game pet-project. While developing I encountered a strange bug.

When I use lipgloss.place in a certain way with zone.mark the whole program and console freezes after responding correctly a few times. Even when I kill the process the console will be stuck without further input being possible. This happens with iterm2 and the default macos terminal. I have to create a new console session to get the console working again.

⛅ Expected behavior

I expected the program to keep processing mouse inputs and not freeze.

🔄 Minimal reproduction

I threw together a minimal example without any of my game logic that keeps freezing on my system:

package main

import (
	"fmt"
	tea "github.com/charmbracelet/bubbletea"
	"github.com/charmbracelet/lipgloss"
	zone "github.com/lrstanley/bubblezone"
	"github.com/muesli/reflow/wordwrap"
	"os"
	"strings"
)

const TriggerBug = true

type TestModel struct {
	size         tea.WindowSizeMsg
	selectedCard int
	numberCards  int
}

func (m TestModel) Init() tea.Cmd {
	return nil
}

func (m TestModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.KeyMsg:
		if msg.String() == "ctrl+c" {
			return m, tea.Quit
		}
	case tea.WindowSizeMsg:
		m.size = msg
	case tea.MouseMsg:
		if msg.Type == tea.MouseLeft || msg.Type == tea.MouseMotion {
			// Check zones to set selected card
			for i := 0; i < m.numberCards; i++ {
				if zone.Get(fmt.Sprintf("%s%d", "card_", i)).InBounds(msg) {
					m.selectedCard = i
				}
			}
		}
	}

	return m, nil
}

func (m TestModel) View() string {
	cardStyle := lipgloss.NewStyle().Width(30).Padding(1, 2).Margin(0, 2)

	var cardBoxes []string
	for i := 0; i < m.numberCards; i++ {
		selected := i == m.selectedCard

		style := cardStyle.
			Border(lipgloss.NormalBorder(), selected, false, false, false).
			BorderBackground(lipgloss.Color("#cccccc")).
			Background(lipgloss.Color("#cccccc")).
			BorderForeground(lipgloss.Color("#ffffff")).
			Foreground(lipgloss.Color("#ffffff"))

		// If the card is selected we give it a bit more height
		if selected {
			cardBoxes = append(cardBoxes,
				style.
					Height(min(m.size.Height-1, m.size.Height/2+5)).
					Render(wordwrap.String(fmt.Sprintf("%s\n\n%s\n\n%s", strings.Repeat("•", 3), "Example Card", "Hello World... Hello World... Hello World.."), 20)),
			)
			continue
		}

		// Non-selected card style
		cardBoxes = append(cardBoxes,
			style.
				Height(m.size.Height/2).
				Render(wordwrap.String(fmt.Sprintf("%s\n\n%s\n\n%s", strings.Repeat("•", 3), "Example Card", "Hello World... Hello World... Hello World.."), 20)),
		)
	}

	for i := range cardBoxes {
		cardBoxes[i] = zone.Mark(fmt.Sprintf("%s%d", "card_", i), cardBoxes[i])
	}

	// EDIT: also breaks after a while
	if !TriggerBug {
		return zone.Scan(lipgloss.JoinHorizontal(lipgloss.Bottom, cardBoxes...))
	}

	// Freeze:
	return zone.Scan(lipgloss.Place(m.size.Width, m.size.Height, lipgloss.Center, lipgloss.Bottom, lipgloss.JoinHorizontal(lipgloss.Bottom, cardBoxes...)))
}

func main() {
	zone.NewGlobal()

	p := tea.NewProgram(TestModel{
		numberCards: 3,
	}, tea.WithAltScreen(), tea.WithMouseAllMotion())
	if _, err := p.Run(); err != nil {
		fmt.Printf("Alas, there's been an error: %v", err)
		os.Exit(1)
	}
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

💠 Version: bubblezone

v0.0.0-20230303230241-08f906ff62a9

🖥 Version: Operating system

macos

⚙ Additional context

Video showing the working lipgloss.JoinHorizontal vs the freezing lipgloss.Place. When the second terminal tab stops responding it's completely frozen. ctrl+c does nothing and I manually need to restart it.

https://streamable.com/65dklc

EDIT: lipgloss.JoinHorizontal also breaks for me after a while

🤝 Requirements

feature: toggle zone markers globally

It'd likely be good to add a feature that allows enabling/disabling the zone manager globally, where calling zone.Mark(v) simply returns the original input, without manipulation. This would make it easier to troubleshoot issues or disable the functionality for users that may not want it.

Also wonder if there is a good solution for having a mode that visually marks zones with a toggle?

bug: The bounds of a zone have a negative number in the end coordinates.

🌧 Describe the problem

When I run zone.Mark() on a certain string, the start and end coords are the following:

StartX: 0
StartY: 0
EndX: -1
EndY: 8

Everything is expected except for EndX
The specific string is 8 lines of 16 colored full block characters (█)

⛅ Expected behavior

I expected the coordinates to be:

StartX: 0
StartY: 0
EndX: 16
EndY: 8

🔄 Minimal reproduction

I don't think I can reproduce it because it seems very specific

💠 Version: bubblezone

v0.0.0-20220822192435-2c9a0c7b4737

🖥 Version: Operating system

linux/ubuntu

⚙ Additional context

Maybe block characters aren't counted, but I tried with multiple different characters (#, and space) and it still happened.

🤝 Requirements

bug: Identifiers show up during list filtering

🌧 Describe the problem

Really impressed with this project, but am coming across an issue with list filtering. When filtering a list with bubblezone, parts of the identifier escape sequences are output in item titles.

⛅ Expected behavior

I would expect list characters to be stripped during filtering.

🔄 Minimal reproduction

  1. Run list-default example.
  2. Type in a filter that matches some items (for example, /ra).
  3. Parts of identifiers are displayed at beginning of item titles.

💠 Version: bubblezone

3cb8c52

🖥 Version: Operating system

macos

⚙ Additional context

Screenshot

image

Other

Would the code that adds the underline be stripping out the escape sequences? It seems like the underline is being added in the wrong place, causing a break in the escape sequences which results in them not being stripped from output.

Examples with escape sequences

Regular title with bubblezone:
�[38;5;213m│�[0m �[38;5;207m�[1001ZRaspberry Pi’s�[1001Z�[0m
Title during filter with bubblezone:
�[38;5;232m�[4;38;5;232;4m��[0m�[4;38;5;232;4m[�[0m�[38;5;232m1001ZRaspberry Pi’s�[1001Z�[0m�[0m
Title during filter without bubblezone:
�[38;5;232m�[4;38;5;232;4mR�[0m�[38;5;232maspberry Pi’s�[0m�[0m

Thank you!

🤝 Requirements

feature: debug mode

✨ Describe the feature you'd like

Would be nice to support extra checks see this issue when developing with bubblezone. For example, bounds checking logic, incorrect usage of markers, and similar.

🌧 Is your feature request related to a problem?

No response

⚠ If implemented, do you think this feature will be a breaking change to users?

No

🤝 Requirements

  • I have confirmed that someone else has not submitted a similar feature request.
  • If implemented, I believe this feature will help others, in addition to solving my problems.
  • I have looked into alternative solutions to the best of my ability.
  • (optional) I would be willing to contribute to testing this feature if implemented, or making a PR to implement this functionality.

bug: Handle zones in non WithAltScreen

🌧 Describe the problem

AltScreen enables a fresh screen and everything starts from the top. But, if I don't use this AltScreen, it seems the zones y position will be calculated wrong. I tested with not having a AltScreen and I noticed my styles triggered when I was at the top with the mouse, although the output was at the bottom. So, it seemed to work, but it essentially triggered like the text was at the top.

I'm not sure how or if this could be solved but it would be nice if this worked somehow. Able to set some offset or even calculate it properly somehow?

⛅ Expected behavior

zones to work in non AltScreen.

🔄 Minimal reproduction

No response

💠 Version: bubblezone

b3469cc

🖥 Version: Operating system

linux/ubuntu

⚙ Additional context

No response

🤝 Requirements

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.