Coder Social home page Coder Social logo

Pager live preview about glow HOT 10 CLOSED

charmbracelet avatar charmbracelet commented on June 18, 2024 4
Pager live preview

from glow.

Comments (10)

muesli avatar muesli commented on June 18, 2024 6

Agreed, that would be nice.

from glow.

shitchell avatar shitchell commented on June 18, 2024 1

Another thing that, imho, would be important is to maintain the scrolling position. When you're editing a really long document you don't want to scroll back to the position of the last change every time.

Totally agreed. in pager.go, you can update the current document by editing the contents of m.currentDocument.Body. Then you run renderWithGlamour(m, m.currentDocument.Body) to re-render/update the view. And it keeps the current position :) As an example, you could drop this into pager.go beneath switch msg.String() { and just above case "q", "esc":

case "1":
	m.currentDocument.Body = m.currentDocument.Body + "\n\nhere's a new line."
	cmd = renderWithGlamour(m, m.currentDocument.Body)
	cmds = append(cmds, cmd)

Then launch glow, open a file, and type "1" repeatedly. It'll keep appending lines to the end of the document, but as the file changes, the scroll position remains the same.

from glow.

mschloesser avatar mschloesser commented on June 18, 2024

I would love to see this feature too! I tried to fiddle with watch and some quick and dirty helper scripts but an actual "live preview" would be great.

from glow.

BachoSeven avatar BachoSeven commented on June 18, 2024

This would close #135 as well.

from glow.

Lisiadito avatar Lisiadito commented on June 18, 2024

I would love to see that feature as well.
@mschloesser can you share your script until the feature is implemented? Because I didn't get it to work with watch.

from glow.

shitchell avatar shitchell commented on June 18, 2024

I feel like this shouldn't be too hard.

https://medium.com/@skdomino/watch-this-file-watching-in-go-5b5a247cf71f

Code would go in pager.go. First, you check to see if the document is stashed or not. If it's not, then using fsnotify, you could create a file watcher to detect any edits to m.currentDocument.localPath. Any time there's an edit, re-read the the contents of m.currentDocument.localPath and update m.currentDocument.Body. Re-render the doc, and you're good.

No promises that I won't get distracted or otherwise not get around to it, but I'll probably look at this over the weekend.

from glow.

shitchell avatar shitchell commented on June 18, 2024

So we've got 3 parts to this:

  1. Initialize a watcher (should only happen once after you launch glow)
  2. Add a new filepath to the watcher (should happen each time you view a local file)
  3. Remove a filepath from the watcher (should happen each time you stop viewing a local file / return to file list)

@meowgorithm @muesli

Do you guys have any suggestions where each step should live? I'm thinking first add the watcher as an attribute of pagerModel. setContent() gets run every time we both open a new file and when we re-render the document (e.g. after detecting a file change). I don't think there presently exists a single method that runs only when we first open a file, so perhaps add another attribute to pager like isViewingFile bool, and then add a block to setContent() such as:

if !isViewingFile:
  isViewingFile = true
  if isLocalFile:
    addWatcher(currentFilePath)

and then toggle isViewingFile to false and remove the watcher whenever you call unload(). Does that seem reasonable? Or would there be a better way to implement this? Since I'm still not super familiar with the code, I wanted to ask before implementing it :P

from glow.

mschloesser avatar mschloesser commented on June 18, 2024

I would love to see that feature as well.
@mschloesser can you share your script until the feature is implemented? Because I didn't get it to work with watch.

@Lisiadito Unfortunately, I deleted the scripts since it didn't really work well.

Another thing that, imho, would be important is to maintain the scrolling position. When you're editing a really long document you don't want to scroll back to the position of the last change every time.

from glow.

morpheusthewhite avatar morpheusthewhite commented on June 18, 2024

Temporary (or maybe not) solution for those who needed this feature to integrate glow it with a terminal editor such as vim: there is this nice plugin https://github.com/npxbr/glow.nvim

from glow.

muesli avatar muesli commented on June 18, 2024

Closing a few tickets describing the same feature. Let's track this in #135, which was the first ticket suggesting it.

from glow.

Related Issues (20)

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.