Skip to content

Commit

Permalink
Merge pull request #1295 from tgy/master
Browse files Browse the repository at this point in the history
[ikhal] add option to disable mouse, fixes #1289
  • Loading branch information
geier authored Oct 24, 2023
2 parents 0395b57 + 5d7daab commit 63c9b85
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ env/
venv/
.hypothesis/
.python-version
.dmypy.json
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ Jason Cox - me [at] jasoncarloscox [dot] com - https://jasoncarloscox.com
Michael Tretter - michael.tretter [at] posteo [dot] net
Raúl Medina - raulmgcontact [at] gmail (dot] com
Matthew Rademaker - matthew.rademaker [at] gmail [dot] com
Valentin Iovene - val [at] too [dot] gy
1 change: 1 addition & 0 deletions khal.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ monthdisplay = firstday
default_calendar = home
timedelta = 2d # the default timedelta that list uses
highlight_event_days = True # the default is False
enable_mouse = True # mouse is enabled by default in interactive mode
20 changes: 18 additions & 2 deletions khal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ def multi_calendar_option(f):
return d(a(f))


def mouse_option(f):
o = click.option(
'--mouse/--no-mouse',
is_flag=True,
default=None,
help='Disable mouse in interactive UI'
)
return o(f)


def _select_one_calendar_callback(ctx, option, calendar):
if isinstance(calendar, tuple):
if len(calendar) > 1:
Expand Down Expand Up @@ -480,9 +490,12 @@ def isatty(_file):

@cli.command()
@multi_calendar_option
@mouse_option
@click.pass_context
def interactive(ctx, include_calendar, exclude_calendar):
def interactive(ctx, include_calendar, exclude_calendar, mouse):
'''Interactive UI. Also launchable via `ikhal`.'''
if mouse is not None:
ctx.obj['conf']['default']['enable_mouse'] = mouse
controllers.interactive(
build_collection(
ctx.obj['conf'],
Expand All @@ -494,10 +507,13 @@ def interactive(ctx, include_calendar, exclude_calendar):
@click.command()
@global_options
@multi_calendar_option
@mouse_option
@click.pass_context
def interactive_cli(ctx, config, include_calendar, exclude_calendar):
def interactive_cli(ctx, config, include_calendar, exclude_calendar, mouse):
'''Interactive UI. Also launchable via `khal interactive`.'''
prepare_context(ctx, config)
if mouse is not None:
ctx.obj['conf']['default']['enable_mouse'] = mouse
controllers.interactive(
build_collection(
ctx.obj['conf'],
Expand Down
4 changes: 4 additions & 0 deletions khal/settings/khal.spec
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ default_event_duration = timedelta(default='1d')
# Define the default duration for an event ('khal new' only)
default_dayevent_duration = timedelta(default='1h')

# Whether the mouse should be enabled in interactive mode ('khal interactive' and
# 'ikhal' only)
enable_mouse = boolean(default=True)


# The view section contains configuration options that effect the visual appearance
# when using khal and ikhal.
Expand Down
7 changes: 6 additions & 1 deletion khal/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,12 @@ def emit(self, record):
palette = _add_calendar_colors(
getattr(colors, pane._conf['view']['theme']), pane.collection)
loop = urwid.MainLoop(
frame, palette, unhandled_input=frame.on_key_press, pop_ups=True)
widget=frame,
palette=palette,
unhandled_input=frame.on_key_press,
pop_ups=True,
handle_mouse=pane._conf['default']['enable_mouse'],
)
frame.loop = loop

def redraw_today(loop, pane, meta=None):
Expand Down
5 changes: 3 additions & 2 deletions tests/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_simple_config(self):
'default_event_duration': dt.timedelta(days=1),
'default_dayevent_duration': dt.timedelta(hours=1),
'show_all_days': False,
'enable_mouse': True,
}
}
for key in comp_config:
Expand Down Expand Up @@ -102,8 +103,8 @@ def test_small(self):
'timedelta': dt.timedelta(days=2),
'default_event_duration': dt.timedelta(days=1),
'default_dayevent_duration': dt.timedelta(hours=1),

'show_all_days': False
'show_all_days': False,
'enable_mouse': True,
}
}
for key in comp_config:
Expand Down

0 comments on commit 63c9b85

Please sign in to comment.