Add support for tab-completion when selecting by rule
[alpine.git] / pith / margin.c
blob3bc5dbe567ff617a758832cea79fd9e1b0615033
1 /*
2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006-2008 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 /*======================================================================
17 margin.c
18 Implements message data gathering and formatting
20 ====*/
23 #include "../pith/headers.h"
24 #include "../pith/string.h"
25 #include "../pith/state.h"
26 #include "../pith/conf.h"
30 * Internal prototypes
35 * format_view_margin - return sane value for vertical margins
37 int *
38 format_view_margin(void)
40 static int margin[2];
41 char tmp[100], e[200], *err, lastchar = 0;
42 int left = 0, right = 0, leftm = 0, rightm = 0;
43 size_t l;
45 memset(margin, 0, sizeof(margin));
48 * We initially tried to make sure that the user didn't shoot themselves
49 * in the foot by setting this too small. People seem to want to do some
50 * strange stuff, so we're going to relax the wild shot detection and
51 * let people set what they want, until we get to the point of totally
52 * absurd. We've also added the possibility of appending the letter c
53 * onto the width. That means treat the value as an absolute column
54 * instead of a width. That is, a right margin of 76c means wrap at
55 * column 76, whereas right margin of 4 means to wrap at column
56 * screen width - 4.
58 if(ps_global->VAR_VIEW_MARGIN_LEFT){
59 strncpy(tmp, ps_global->VAR_VIEW_MARGIN_LEFT, sizeof(tmp)-1);
60 tmp[sizeof(tmp)-1] = '\0';
61 removing_leading_and_trailing_white_space(tmp);
62 if(tmp[0]){
63 l = strlen(tmp);
64 if(l > 0)
65 lastchar = tmp[l-1];
67 if(lastchar == 'c')
68 tmp[l-1] = '\0';
70 if((err = strtoval(tmp, &left, 0, 0, 0, e, sizeof(e), "Viewer-margin-left")) != NULL){
71 leftm = 0;
72 dprint((2, "%s\n", err));
74 else{
75 if(lastchar == 'c')
76 leftm = left-1;
77 else
78 leftm = left;
80 leftm = MIN(MAX(0, leftm), ps_global->ttyo->screen_cols);
85 if(ps_global->VAR_VIEW_MARGIN_RIGHT){
86 strncpy(tmp, ps_global->VAR_VIEW_MARGIN_RIGHT, sizeof(tmp)-1);
87 tmp[sizeof(tmp)-1] = '\0';
88 removing_leading_and_trailing_white_space(tmp);
89 if(tmp[0]){
90 l = strlen(tmp);
91 if(l > 0)
92 lastchar = tmp[l-1];
94 if(lastchar == 'c')
95 tmp[l-1] = '\0';
97 if((err = strtoval(tmp, &right, 0, 0, 0, e, sizeof(e), "Viewer-margin-right")) != NULL){
98 rightm = 0;
99 dprint((2, "%s\n", err));
101 else{
102 if(lastchar == 'c')
103 rightm = ps_global->ttyo->screen_cols - right;
104 else
105 rightm = right;
107 rightm = MIN(MAX(0, rightm), ps_global->ttyo->screen_cols);
112 if((rightm > 0 || leftm > 0) && rightm >= 0 && leftm >= 0
113 && ps_global->ttyo->screen_cols - rightm - leftm >= 8){
114 margin[0] = leftm;
115 margin[1] = rightm;
118 return(margin);
123 * Give a margin for help and such
125 int *
126 non_messageview_margin(void)
128 static int margin[2];
130 margin[0] = 0;
131 margin[1] = 4;
133 return(margin);