From 2e8500753ad6de64a22eb3bb69573ce7b1bc539a Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Wed, 26 Apr 2023 06:31:31 +0900 Subject: [PATCH] Make using balance mode consistent with mask mode Mask mode is toggled using an enable function and a disable function. Despite being a similar binary mode, balance mode is toggled using a single function that takes an argument specifying the status of the mode. No preference is expressed as to which API is better but since balance mode has only recently been added, this change makes balance mode match the approach taken by mask mode. --- bestline.c | 15 ++++++++++++--- bestline.h | 3 ++- example.c | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bestline.c b/bestline.c index ba2654d..62e66be 100644 --- a/bestline.c +++ b/bestline.c @@ -3612,13 +3612,22 @@ void bestlineMaskModeDisable(void) { } /** - * Enables or disables "balance mode". + * Enables "balance mode". * * When it is enabled, bestline() will block until parentheses are * balanced. This is useful for code but not for free text. + * + * @see bestlineBalanceModeDisable() + */ +void bestlineBalanceModeEnable(void) { + balancemode = 1; +} + +/** + * Disables "balance mode". */ -void bestlineBalanceMode(char mode) { - balancemode = mode; +void bestlineBalanceModeDisable(void) { + balancemode = 0; } /** diff --git a/bestline.h b/bestline.h index 93653dc..23c4bbe 100644 --- a/bestline.h +++ b/bestline.h @@ -30,7 +30,8 @@ void bestlineHistoryFree(void); void bestlineClearScreen(int); void bestlineMaskModeEnable(void); void bestlineMaskModeDisable(void); -void bestlineBalanceMode(char); +void bestlineBalanceModeEnable(void); +void bestlineBalanceModeDisable(void); void bestlineUserIO(void *userReadFn, void *userWriteFn, void *userPollFn); void bestlineDisableRawMode(void); void bestlineFree(void *); diff --git a/example.c b/example.c index 90cc7cd..8750a2b 100644 --- a/example.c +++ b/example.c @@ -69,9 +69,9 @@ int main(int argc, char **argv) { } else if (!strncmp(line, "/unmask", 7)) { bestlineMaskModeDisable(); } else if (!strncmp(line, "/balance", 8)) { - bestlineBalanceMode(1); + bestlineBalanceModeEnable(); } else if (!strncmp(line, "/unbalance", 10)) { - bestlineBalanceMode(0); + bestlineBalanceModeDisable(); } else if (line[0] == '/') { fputs("Unreconized command: ", stdout); fputs(line, stdout);