Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ikhal] add option to disable mouse, fixes #1289 #1295

Merged
merged 8 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this because I'm using neovim with pylsp-mypy (with the dmypy daemon, which can create this file).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections on this.

Note that you can include this in ~/.config/git/ignore and git will ignore the file for all your local repositories.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks, did not know that. Good to know :)

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
16 changes: 14 additions & 2 deletions khal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def multi_calendar_option(f):
return d(a(f))


def no_mouse_option(f):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I had to use this both for ikhal and khal interactive, I figured it made sense to abstract this option into its own function decorator.

o = click.option('--mouse/--no-mouse', is_flag=True, default=True
choucavalier marked this conversation as resolved.
Show resolved Hide resolved
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 +486,12 @@ def isatty(_file):

@cli.command()
@multi_calendar_option
@no_mouse_option
@click.pass_context
def interactive(ctx, include_calendar, exclude_calendar):
def interactive(ctx, include_calendar, exclude_calendar, no_mouse):
choucavalier marked this conversation as resolved.
Show resolved Hide resolved
'''Interactive UI. Also launchable via `ikhal`.'''
if no_mouse:
ctx.obj['conf']['default']['enable_mouse'] = False
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm overriding the config value when the --no-mouse flag is used. Not sure this is the best way, but seems to work.

controllers.interactive(
build_collection(
ctx.obj['conf'],
Expand All @@ -494,10 +503,13 @@ def interactive(ctx, include_calendar, exclude_calendar):
@click.command()
@global_options
@multi_calendar_option
@no_mouse_option
@click.pass_context
def interactive_cli(ctx, config, include_calendar, exclude_calendar):
def interactive_cli(ctx, config, include_calendar, exclude_calendar, no_mouse):
choucavalier marked this conversation as resolved.
Show resolved Hide resolved
'''Interactive UI. Also launchable via `khal interactive`.'''
prepare_context(ctx, config)
if no_mouse:
ctx.obj['conf']['default']['enable_mouse'] = False
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,
WhyNotHugo marked this conversation as resolved.
Show resolved Hide resolved
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
Loading