hstr icon indicating copy to clipboard operation
hstr copied to clipboard

Option to change height (number of lines)

Open qazip opened this issue 6 years ago • 1 comments

It would be awesome if we could change the height of hstr. I don't like having it full-terminal, I would like to see only, say, 10 lines.

qazip avatar Jul 07 '19 08:07 qazip

@dvorka @qazip hi, You can change height with this patch

--- hstr.c-orig	2023-12-31 11:27:11.000000000 +0100
+++ hstr.c	2023-12-31 13:24:12.587337594 +0100
@@ -93,6 +93,9 @@
 #define HSTR_CONFIG_BIG_KEYS_FLOOR          "big-keys-floor"
 #define HSTR_CONFIG_BIG_KEYS_EXIT           "big-keys-exit"
 #define HSTR_CONFIG_DUPLICATES              "duplicates"
+// ADD_CODE
+#define HSTR_CONFIG_MAX_HEIGHT              "max-height"
+//-ADD_CODE
 
 #define HSTR_DEBUG_LEVEL_NONE  0
 #define HSTR_DEBUG_LEVEL_WARN  1
@@ -267,6 +270,9 @@
     int promptYItemsStart;
     int promptYItemsEnd;
     int promptItems;
+    // ADD_CODE
+    int config_max_height;  // La hauteur maximale souhaitée
+    // -ADD_CODE
 
     bool noIoctl;
 } Hstr;
@@ -429,6 +435,17 @@
 unsigned recalculate_max_history_items(void)
 {
     int n = getmaxy(stdscr);
+
+    // ADD_CODE
+    int default_max_height = 20;  // Définissez la hauteur maximale par défaut
+
+    int max_height = (hstr->config_max_height != 0) ? hstr->config_max_height : default_max_height;
+
+    if (n > max_height) {
+        n = max_height;
+    }
+    // -ADD_CODE
+
     hstr->promptItems = n-1;
     if(!hstr->hideBasicHelp) {
         hstr->promptItems--;
@@ -530,6 +547,12 @@
             }
         }
     }
+    // ADD_CODE
+    if(hstr->promptItems > max_height) {
+        hstr->promptItems = max_height;
+    }
+    // -ADD_CODE
+
     return hstr->promptItems;
 }
 
@@ -537,6 +560,21 @@
 {
     char *hstr_config=getenv(HSTR_ENV_VAR_CONFIG);
     if(hstr_config && strlen(hstr_config)>0) {
+
+        // ADD_CODE
+
+        if(strstr(hstr_config, HSTR_CONFIG_MAX_HEIGHT)) {
+            char *maxHeightStr = strstr(hstr_config, HSTR_CONFIG_MAX_HEIGHT) + strlen(HSTR_CONFIG_MAX_HEIGHT) + 1;
+            char *endPtr;
+            long maxHeightVal = strtol(maxHeightStr, &endPtr, 10);
+            if(maxHeightStr != endPtr) { // Vérifiez que la conversion a réussi
+                hstr->config_max_height = (int)maxHeightVal;
+            }
+        }
+
+        // -ADD_CODE
+
+
         if(strstr(hstr_config,HSTR_CONFIG_THEME_MONOCHROMATIC)) {
             hstr->theme=HSTR_THEME_MONO;
         } else {
@@ -1089,6 +1127,7 @@
     }
 
     unsigned height=recalculate_max_history_items();
+
     unsigned width=getmaxx(stdscr);
     unsigned i;
     int y;

copy it in patch_file, save it in the src directory, then execute this commands from src directory

mv hstr.c hstr.c-orig
patch < parch_file

then rebuid hstr

Now you can add

export HSTR_CONFIG=max-height:10, hicolor

at your .bashrc

you can set the max-height value, here is 10

This code doesn't manage max and min value so be care to what you set.

rcspam avatar Dec 31 '23 12:12 rcspam