Skip to content

Commit

Permalink
fix: jans-cli-tui refactor mouse operations (#3482)
Browse files Browse the repository at this point in the history
* fix: jans-cli-tui refactor mouse operations

* fix: jans-cli-tui delete_uma_resource
  • Loading branch information
devrimyatar authored Jan 2, 2023
1 parent ea06660 commit 39dc0c7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 97 deletions.
163 changes: 67 additions & 96 deletions jans-cli-tui/cli_tui/jans_cli_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import asyncio
import concurrent.futures

from enum import Enum
from pathlib import Path
from itertools import cycle
from requests.models import Response
Expand Down Expand Up @@ -392,8 +393,7 @@ def set_keybindings(self) -> None:
self.bindings.add(Keys.Vt100MouseEvent)(self.mouse)



def mouse(self,event): ### mouse: [<35;108;20M
def mouse(self, event): ### mouse: [<35;108;20M

pieces = event.data.split(";") ##['LEFT', 'MOUSE_DOWN', '146', '10']
mouse_click=int(pieces[0][3:])
Expand Down Expand Up @@ -425,134 +425,105 @@ def mouse(self,event): ### mouse: [<35;108;20M
style_tmp = '<style >{}</style>'
style_tmp_red = '<style fg="ansired" bg="#00FF00">{}</style>'

class mouse_operations(Enum):
Copy = 1
Cut = 2
Paste = 3

res=[]
res.append(HTML(style_tmp.format("Copy")))
res.append("\n")
res.append(HTML(style_tmp.format("Cut")))
res.append("\n")
res.append(HTML(style_tmp.format("Paste")))
res.append("\n")

content= Window(
for mouse_op in mouse_operations:
res.append(HTML(style_tmp.format(mouse_op.name)))
res.append("\n")

content = Window(
content=FormattedTextControl(
text=merge_formatted_text(res),
focusable=True,
), height=D())
floa=Float(content=content, left=x,top=y)
floa.name='mouse'
mouse_float_container = Float(content=content, left=x,top=y)
mouse_float_container.name = 'mouse'

# ------------------------------------------------------------------------------------ #
# ------------------------------------------------------------------------------------ #
# ------------------------------------------------------------------------------------ #

if mouse_click == "RIGHT" and mouse_event == MouseEventType.MOUSE_DOWN :
if self.mouse_float == True :
self.root_layout.floats.append(floa)
self.root_layout.floats.append(mouse_float_container)
self.mouse_cord=(x,y)
self.mouse_float = False
else:
try:
if get_app().layout.container.floats:
if get_app().layout.container.floats[-1].name =='mouse':
get_app().layout.container.floats.remove(get_app().layout.container.floats[-1])
self.root_layout.floats.append(floa)
if self.layout.container.floats:
if self.layout.container.floats[-1].name =='mouse':
self.layout.container.floats.remove(self.layout.container.floats[-1])
self.root_layout.floats.append(mouse_float_container)
self.mouse_cord=(x,y)
self.mouse_float = False
else:
self.root_layout.floats.append(floa)
self.root_layout.floats.append(mouse_float_container)
self.mouse_cord=(x,y)
self.mouse_float = False
else:
self.root_layout.floats.append(floa)
self.root_layout.floats.append(mouse_float_container)
self.mouse_cord=(x,y)
self.mouse_float = False
except Exception:
pass

elif mouse_click == "LEFT" and mouse_event == MouseEventType.MOUSE_DOWN and self.mouse_float == False:
try:
if get_app().layout.container.floats:
if get_app().layout.container.floats[-1].name =='mouse':

if self.mouse_select =='Copy':
data = get_app().current_buffer.copy_selection(False)
get_app().clipboard.set_data(data)
get_app().layout.container.floats.remove(get_app().layout.container.floats[-1])
self.mouse_float = True

elif self.mouse_select =='Paste':
data = get_app().clipboard.get_data()
get_app().current_buffer.paste_clipboard_data(data)
get_app().layout.container.floats.remove(get_app().layout.container.floats[-1])
self.mouse_float = True

elif self.mouse_select =='Cut':
data = get_app().current_buffer.copy_selection(True)
get_app().clipboard.set_data(data)
get_app().layout.container.floats.remove(get_app().layout.container.floats[-1])
self.mouse_float = True

else:
get_app().layout.container.floats.remove(get_app().layout.container.floats[-1])
self.mouse_float = True

if self.layout.container.floats:
if self.layout.container.floats[-1].name == 'mouse':
self.layout.container.floats.remove(self.layout.container.floats[-1])
self.mouse_float = True
if self.mouse_select == mouse_operations.Copy.name:
data = self.current_buffer.copy_selection(False)
self.clipboard.set_data(data)
elif self.mouse_select == mouse_operations.Paste.name:
data = self.clipboard.get_data()
self.current_buffer.paste_clipboard_data(data)
elif self.mouse_select == mouse_operations.Cut.name:
data = self.current_buffer.copy_selection(True)
self.clipboard.set_data(data)
except Exception:
pass


if get_app().layout.container.floats:

if self.layout.container.floats:
try :
get_float_name = get_app().layout.container.floats[-1].name
get_float_name = self.layout.container.floats[-1].name
except Exception:
get_float_name = ''

if get_float_name =='mouse':
if get_float_name == 'mouse':

if self.mouse_cord[0] <= x and self.mouse_cord[0] >= x-5:
if self.mouse_cord[1] == y-1:
res = []
res.append(HTML(style_tmp_red.format("Copy ")))
res.append("\n")
res.append(HTML(style_tmp.format("Cut")))
res.append("\n")
res.append(HTML(style_tmp.format("Paste")))
res.append("\n")
get_app().layout.container.floats[-1].content.content.text=merge_formatted_text(res)
self.mouse_select = 'Copy'
elif self.mouse_cord[1] == y-2:
res = []
res.append(HTML(style_tmp.format("Copy")))
res.append("\n")
res.append(HTML(style_tmp_red.format("Cut ")))
res.append("\n")
res.append(HTML(style_tmp.format("Paste")))
res.append("\n")
get_app().layout.container.floats[-1].content.content.text=merge_formatted_text(res)
self.mouse_select = 'Cut'
elif self.mouse_cord[1] == y-3:
res = []
res.append(HTML(style_tmp.format("Copy")))
res.append("\n")
res.append(HTML(style_tmp.format("Cut")))
res.append("\n")
res.append(HTML(style_tmp_red.format("Paste")))
res.append("\n")
get_app().layout.container.floats[-1].content.content.text=merge_formatted_text(res)
self.mouse_select = 'Paste'
res = []
if self.mouse_cord[1] in [y - mouse_op.value for mouse_op in mouse_operations]:
for mouse_op in mouse_operations:
tmp_ = style_tmp
if self.mouse_cord[1] == y - mouse_op.value:
self.mouse_select = mouse_op.name
tmp_ = style_tmp_red
res.append(HTML(tmp_.format(mouse_op.name.ljust(5))))
res.append("\n")
else:
self.mouse_select = 'None'
self.mouse_select = None

if res:
self.layout.container.floats[-1].content.content.text=merge_formatted_text(res)

else:
res = []
res.append(HTML(style_tmp.format("Copy")))
res = []
for mouse_op in mouse_operations:
res.append(HTML(style_tmp.format(mouse_op.name)))
res.append("\n")
res.append(HTML(style_tmp.format("Cut")))
res.append("\n")
res.append(HTML(style_tmp.format("Paste")))
res.append("\n")
get_app().layout.container.floats[-1].content.content.text=merge_formatted_text(res)
self.mouse_select = 'None'
self.layout.container.floats[-1].content.content.text=merge_formatted_text(res)
self.mouse_select = None


def up(self, ev: KeyPressEvent) -> None:
get_app().layout.focus(Frame(self.nav_bar.nav_window))
self.layout.focus(Frame(self.nav_bar.nav_window))

def focus_next(self, ev: KeyPressEvent) -> None:
focus_next(ev)
Expand All @@ -567,13 +538,13 @@ def help(self,ev: KeyPressEvent) -> None:

def escape(self,ev: KeyPressEvent) -> None:
try:
if get_app().layout.container.floats:
if len(get_app().layout.container.floats) >=2 :
get_app().layout.container.floats.remove(get_app().layout.container.floats[-1])
get_app().layout.focus(get_app().layout.container.floats[-1].content)
if self.layout.container.floats:
if len(self.layout.container.floats) >=2 :
self.layout.container.floats.remove(self.layout.container.floats[-1])
self.layout.focus(self.layout.container.floats[-1].content)
else:
get_app().layout.container.floats.remove(get_app().layout.container.floats[0])
get_app().layout.focus(self.center_frame)
self.layout.container.floats.remove(self.layout.container.floats[0])
self.layout.focus(self.center_frame)
except Exception as e:
pass

Expand Down
2 changes: 1 addition & 1 deletion jans-cli-tui/cli_tui/plugins/010_auth_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ async def coroutine():

asyncio.ensure_future(coroutine())

def delete_UMAresource(self, **kwargs: Any):
def delete_uma_resource(self, **kwargs: Any):
"""This method for the deletion of the UMAresource
Returns:
Expand Down

0 comments on commit 39dc0c7

Please sign in to comment.