bpython / curtsies

Curses-like terminal wrapper with a display based on compositing 2d arrays of text.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Center content in FSArrays

thomasballinger opened this issue · comments

Spurred by https://twitter.com/TAThorogood/status/1284650865991626754?s=20, some basic bits of a content layout system could be useful.

We could start with methods for centering content in an array, arr.center(content) I suppose?

Sorry, I'm confused. Arr.center is just window.width - len(content) // 2? Or is it something more?

Yes roughly, plus on the vertical axis. Like

arr = FSArray(window.height, window.width)
arr.center("hello")

producing something like (if it's side-effecting, I have no idea what I was thinking at the time)




                        hello       
       
       
      

so equivalent to

arr = FSArray(window.height, window.width)
arr[arr.height // 2][arr.width - len(content) // 2 : arr.width + (len(content) + 1) // 2] = content