Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
willhbr committed Mar 8, 2024
1 parent 082133d commit a673e8b
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 31 deletions.
4 changes: 4 additions & 0 deletions Containerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM docker.io/python:latest
WORKDIR /src
ENTRYPOINT ["python", "main.py"]

98 changes: 98 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import ast
import sys
import textwrap

class Program:
def __init__(self):
self.session = 'test-session'
self.buffer = []
self.index = 0

def next_window_index(self):
self.index += 1
return self.index
def write(self, contents):
self.buffer.append(textwrap.dedent(contents))
def to_string(self):
return '\n'.join(self.buffer)

def add_header(self):
self.write("""\
new-session -d -n %s 'read && tmux wait-for -S %s'
set -g display-time 0
set -g focus-events on
""" % (self.session, self.session))

def push_constant(self, value):
index = self.next_window_index()
self.write("""\
new-window 'tmux wait-for %s'
set-hook -t :=%s pane-focus-in {
run "tmux set-buffer '%s'"
run 'tmux next-window'
}
""" % (self.session, index, value))

def store_top(self, out_index=None):
index = self.next_window_index()
self.write("""\
new-window 'tmux wait-for %s'
set-hook -t :=%s pane-focus-in {
run 'tmux rename-window -t :=%s "#{buffer_sample}"'
run 'tmux delete-buffer'
run 'tmux next-window'
}
""" % (self.session, index, index + 1 if out_index is None else out_index))

def maths_op(self, op):
index = self.next_window_index()
self.write("""\
new-window 'tmux wait-for %s'
set-hook -t :=%s pane-focus-in {
run 'tmux rename-window -t :=4 "#{e|%s:#{buffer_sample},#{window_name}}"'
run 'tmux delete-buffer'
run 'tmux set-buffer "#{window_name}"'
run 'tmux next-window'
}
""" % (self.session, index, op))

def print(self):
index = self.next_window_index()
self.write("""\
new-window 'tmux wait-for %s'
set-hook -t :=%s pane-focus-in {
run 'tmux display -F "#{buffer_sample}"'
run 'tmux delete-buffer'
run 'tmux next-window'
}
""" % (self.session, index))

def ifeq(self):
pass
#new-window 'tmux wait-for test-session'
#set-hook -t :=4 pane-focus-in {
# run 'tmux select-window -t "#{?#{e|==:#{buffer_sample},#{window_name}},:=5,:=6}"'
# run 'tmux delete-buffer'
#}


p = Program()
p.add_header()
p.push_constant(1)
p.push_constant(2)
p.store_top()
p.maths_op('+')
p.print()
p.write('select-window -t :=0')

print(p.to_string())


with open(sys.argv[1]) as f:
tree = ast.parse(f.read())

print(ast.dump(tree, indent=2))

with open(sys.argv[2], 'wt') as o:
o.write(p.to_string())

14 changes: 14 additions & 0 deletions pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
containers:
dev:
name: tmux-compiler-dev
image: docker.io/library/python:latest
interactive: true
autoremove: true
bind_mounts:
# binding the source directory lets us re-run changes without rebuilding
.: /src
run_flags:
entrypoint:
- python
- main.py
workdir: /src
1 change: 1 addition & 0 deletions program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print(1 + 2)
39 changes: 39 additions & 0 deletions test.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
new-session -d -n test-session 'read && tmux wait-for -S test-session'
set -g display-time 0
set -g focus-events on

new-window 'tmux wait-for test-session'
set-hook -t :=1 pane-focus-in {
run "tmux set-buffer '1'"
run 'tmux next-window'
}

new-window 'tmux wait-for test-session'
set-hook -t :=2 pane-focus-in {
run "tmux set-buffer '2'"
run 'tmux next-window'
}

new-window 'tmux wait-for test-session'
set-hook -t :=3 pane-focus-in {
run 'tmux rename-window -t :=4 "#{buffer_sample}"'
run 'tmux delete-buffer'
run 'tmux next-window'
}

new-window 'tmux wait-for test-session'
set-hook -t :=4 pane-focus-in {
run 'tmux rename-window -t :=4 "#{e|+:#{buffer_sample},#{window_name}}"'
run 'tmux delete-buffer'
run 'tmux set-buffer "#{window_name}"'
run 'tmux next-window'
}

new-window 'tmux wait-for test-session'
set-hook -t :=5 pane-focus-in {
run 'tmux display -F "#{buffer_sample}"'
run 'tmux delete-buffer'
run 'tmux next-window'
}

select-window -t :=0
50 changes: 19 additions & 31 deletions tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set-hook -t :=1 pane-focus-in {
# push 2
new-window 'tmux wait-for test-session'
set-hook -t :=2 pane-focus-in {
run "tmux set-buffer '1'"
run "tmux set-buffer '2'"
run 'tmux next-window'
}
# store top
Expand All @@ -21,40 +21,28 @@ set-hook -t :=3 pane-focus-in {
run 'tmux delete-buffer'
run 'tmux next-window'
}
# # add
# new-window 'tmux wait-for test-session'
# set-hook -t :=4 pane-focus-in {
# run 'tmux rename-window -t :=4 "#{e|+:#{buffer_sample},#{window_name}}"'
# run 'tmux delete-buffer'
# run 'tmux set-buffer "#{window_name}"'
# run 'tmux next-window'
# }
# comp
# add
new-window 'tmux wait-for test-session'
set-hook -t :=4 pane-focus-in {
run 'tmux select-window -t "#{?#{e|==:#{buffer_sample},#{window_name}},:=5,:=6}"'
run 'tmux rename-window -t :=4 "#{e|+:#{buffer_sample},#{window_name}}"'
run 'tmux delete-buffer'
run 'tmux set-buffer "#{window_name}"'
run 'tmux next-window'
}
new-window
new-window
# comp
#new-window 'tmux wait-for test-session'
#set-hook -t :=4 pane-focus-in {
# run 'tmux select-window -t "#{?#{e|==:#{buffer_sample},#{window_name}},:=5,:=6}"'
# run 'tmux delete-buffer'
#}
#new-window
#new-window
# # display
# new-window 'tmux wait-for test-session'
# set-hook -t :=5 pane-focus-in {
# run 'tmux display -F "#{buffer_sample}"'
# run 'tmux delete-buffer'
# run 'tmux next-window'
# }
new-window 'tmux wait-for test-session'
set-hook -t :=5 pane-focus-in {
run 'tmux display -F "#{buffer_sample}"'
run 'tmux delete-buffer'
run 'tmux next-window'
}

select-window -t :=0


# new-window
# new-window
# set-hook -t :=0 pane-focus-in {
# rename-window -t :=1 firstbutt
# run "tmux select-window -t :=1"
# }
# set-hook -t :=1 pane-focus-in {
# display "oh no"
# }
#

0 comments on commit a673e8b

Please sign in to comment.