2
copyright 2002, 2003 Alexander Malmberg <alexander@malmberg.org>
4
This file is a part of Terminal.app. Terminal.app is free software; you
5
can redistribute it and/or modify it under the terms of the GNU General
6
Public License as published by the Free Software Foundation; version 2
7
of the License. See COPYING or main.m for more information.
10
#include <Foundation/NSNotification.h>
11
#include <Foundation/NSString.h>
12
#include <Foundation/NSUserDefaults.h>
13
#include <AppKit/NSBox.h>
14
#include <AppKit/NSColor.h>
15
#include <AppKit/NSColorPanel.h>
16
#include <AppKit/NSColorWell.h>
17
#include <AppKit/NSFont.h>
18
#include <AppKit/NSGraphics.h>
19
#include <AppKit/NSImage.h>
20
#include <AppKit/NSTextField.h>
21
#include <GNUstepGUI/GSVbox.h>
22
#include <GNUstepGUI/GSHbox.h>
25
#include "TerminalViewPrefs.h"
28
NSString *TerminalViewDisplayPrefsDidChangeNotification=
29
@"TerminalViewDisplayPrefsDidChangeNotification";
31
static NSUserDefaults *ud;
35
*TerminalFontKey=@"TerminalFont",
36
*TerminalFontSizeKey=@"TerminalFontSize",
37
*BoldTerminalFontKey=@"BoldTerminalFont",
38
*BoldTerminalFontSizeKey=@"BoldTerminalFontSize",
39
*UseMultiCellGlyphsKey=@"UseMultiCellGlyphs",
40
*CursorStyleKey=@"CursorStyle",
41
*ScrollBackLinesKey=@"ScrollBackLines",
43
*CursorColorRKey=@"CursorColorR",
44
*CursorColorGKey=@"CursorColorG",
45
*CursorColorBKey=@"CursorColorB",
46
*CursorColorAKey=@"CursorColorA";
49
static NSFont *terminalFont,*boldTerminalFont;
51
static BOOL useMultiCellGlyphs;
53
static float brightness[3]={0.6,0.8,1.0};
54
static float saturation[3]={1.0,1.0,0.75};
56
static int cursorStyle;
57
static NSColor *cursorColor;
59
static int scrollBackLines;
62
@implementation TerminalViewDisplayPrefs
67
ud=[NSUserDefaults standardUserDefaults];
75
size=[ud floatForKey: TerminalFontSizeKey];
76
s=[ud stringForKey: TerminalFontKey];
78
terminalFont=[[NSFont userFixedPitchFontOfSize: size] retain];
81
terminalFont=[[NSFont fontWithName: s size: size] retain];
83
terminalFont=[[NSFont userFixedPitchFontOfSize: size] retain];
86
size=[ud floatForKey: BoldTerminalFontSizeKey];
87
s=[ud stringForKey: BoldTerminalFontKey];
89
boldTerminalFont=[[NSFont userFixedPitchFontOfSize: size] retain];
92
boldTerminalFont=[[NSFont fontWithName: s size: size] retain];
93
if (!boldTerminalFont)
94
boldTerminalFont=[[NSFont userFixedPitchFontOfSize: size] retain];
97
useMultiCellGlyphs=[ud boolForKey: UseMultiCellGlyphsKey];
99
cursorStyle=[ud integerForKey: CursorStyleKey];
100
if ([ud objectForKey: CursorColorRKey])
103
r=[ud floatForKey: CursorColorRKey];
104
g=[ud floatForKey: CursorColorGKey];
105
b=[ud floatForKey: CursorColorBKey];
106
a=[ud floatForKey: CursorColorAKey];
107
cursorColor=[[NSColor colorWithCalibratedRed: r
114
cursorColor=[[NSColor whiteColor] retain];
117
scrollBackLines=[ud integerForKey: ScrollBackLinesKey];
118
if (scrollBackLines<=0)
123
+(NSFont *) terminalFont
125
NSFont *f=[terminalFont screenFont];
131
+(NSFont *) boldTerminalFont
133
NSFont *f=[boldTerminalFont screenFont];
136
return boldTerminalFont;
139
+(BOOL) useMultiCellGlyphs
141
return useMultiCellGlyphs;
144
+(const float *) brightnessForIntensities
148
+(const float *) saturationForIntensities
158
+(NSColor *) cursorColor
163
+(int) scrollBackLines
165
return scrollBackLines;
173
cursorStyle=[[m_cursorStyle selectedCell] tag];
174
[ud setInteger: cursorStyle
175
forKey: CursorStyleKey];
178
DESTROY(cursorColor);
179
cursorColor=[w_cursorColor color];
180
cursorColor=[[cursorColor colorUsingColorSpaceName: NSCalibratedRGBColorSpace] retain];
181
[ud setFloat: [cursorColor redComponent]
182
forKey: CursorColorRKey];
183
[ud setFloat: [cursorColor greenComponent]
184
forKey: CursorColorGKey];
185
[ud setFloat: [cursorColor blueComponent]
186
forKey: CursorColorBKey];
187
[ud setFloat: [cursorColor alphaComponent]
188
forKey: CursorColorAKey];
191
ASSIGN(terminalFont,[f_terminalFont font]);
192
[ud setFloat: [terminalFont pointSize]
193
forKey: TerminalFontSizeKey];
194
[ud setObject: [terminalFont fontName]
195
forKey: TerminalFontKey];
197
ASSIGN(boldTerminalFont,[f_boldTerminalFont font]);
198
[ud setFloat: [boldTerminalFont pointSize]
199
forKey: BoldTerminalFontSizeKey];
200
[ud setObject: [boldTerminalFont fontName]
201
forKey: BoldTerminalFontKey];
203
scrollBackLines=[f_scrollBackLines intValue];
204
[ud setInteger: scrollBackLines
205
forKey: ScrollBackLinesKey];
207
useMultiCellGlyphs=!![b_useMultiCellGlyphs state];
208
[ud setBool: useMultiCellGlyphs
209
forKey: UseMultiCellGlyphsKey];
211
[[NSNotificationCenter defaultCenter]
212
postNotificationName: TerminalViewDisplayPrefsDidChangeNotification
220
[b_useMultiCellGlyphs setState: useMultiCellGlyphs];
222
[m_cursorStyle selectCellWithTag: [[self class] cursorStyle]];
223
[w_cursorColor setColor: [[self class] cursorColor]];
225
f=[isa terminalFont];
226
[f_terminalFont setStringValue: [NSString stringWithFormat: @"%@ %0.1f",[f fontName],[f pointSize]]];
227
[f_terminalFont setFont: f];
229
f=[isa boldTerminalFont];
230
[f_boldTerminalFont setStringValue: [NSString stringWithFormat: @"%@ %0.1f",[f fontName],[f pointSize]]];
231
[f_boldTerminalFont setFont: f];
233
[f_scrollBackLines setIntValue: scrollBackLines];
239
return _(@"Display");
242
-(void) setupButton: (NSButton *)b
244
[b setTitle: _(@"Display")];
256
top=[[GSVbox alloc] init];
257
[top setDefaultMinYMargin: 2];
259
[top addView: [[[NSView alloc] init] autorelease] enablingYResizing: YES];
266
hb=[[GSHbox alloc] init];
267
[hb setDefaultMinXMargin: 4];
268
[hb setAutoresizingMask: NSViewWidthSizable];
270
f=[NSTextField newLabel: _(@"Scroll-back length in lines:")];
271
[f setAutoresizingMask: 0];
272
[hb addView: f enablingXResizing: NO];
275
f_scrollBackLines=f=[[NSTextField alloc] init];
276
[f setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
278
[hb addView: f enablingXResizing: YES];
281
[top addView: hb enablingYResizing: NO];
284
[top addView: [[[NSView alloc] init] autorelease] enablingYResizing: YES];
291
b=[[NSBox alloc] init];
292
[b setAutoresizingMask: NSViewMinXMargin|NSViewMaxXMargin];
293
[b setTitle: _(@"Cursor")];
295
t=[[GSTable alloc] initWithNumberOfRows: 2 numberOfColumns: 2];
296
[t setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
298
f=[NSTextField newLabel: _(@"Style:")];
299
[f setAutoresizingMask: NSViewMinXMargin|NSViewMinYMargin|NSViewMaxYMargin];
300
[t putView: f atRow: 0 column: 0 withXMargins: 2 yMargins: 2];
305
NSButtonCell *b=[NSButtonCell new];
308
[b setImagePosition: NSImageOnly];
309
[b setHighlightsBy: NSChangeBackgroundCellMask];
310
[b setShowsStateBy: NSChangeBackgroundCellMask];
312
m=m_cursorStyle=[[NSMatrix alloc] initWithFrame: NSMakeRect(0,0,1,1)
313
mode: NSRadioModeMatrix
318
[[m cellAtRow: 0 column: 0] setImage: [NSImage imageNamed: @"cursor_line"]];
319
[[m cellAtRow: 0 column: 1] setImage: [NSImage imageNamed: @"cursor_stroked"]];
320
[[m cellAtRow: 0 column: 2] setImage: [NSImage imageNamed: @"cursor_filled"]];
321
[[m cellAtRow: 0 column: 3] setImage: [NSImage imageNamed: @"cursor_inverted"]];
322
[[m cellAtRow: 0 column: 0] setTag: 0];
323
[[m cellAtRow: 0 column: 1] setTag: 1];
324
[[m cellAtRow: 0 column: 2] setTag: 2];
325
[[m cellAtRow: 0 column: 3] setTag: 3];
327
s=[[m cellAtRow: 0 column: 0] cellSize];
333
[t putView: m atRow: 0 column: 1 withXMargins: 2 yMargins: 2];
338
f=[NSTextField newLabel: _(@"Color:")];
339
[f setAutoresizingMask: NSViewMinXMargin|NSViewMinYMargin|NSViewMaxYMargin];
340
[t putView: f atRow: 1 column: 0 withXMargins: 2 yMargins: 2];
343
w_cursorColor=w=[[NSColorWell alloc] initWithFrame: NSMakeRect(0,0,40,30)];
344
[t putView: w atRow: 1 column: 1 withXMargins: 2 yMargins: 2];
347
[[NSColorPanel sharedColorPanel] setShowsAlpha: YES];
351
[b setContentView: t];
353
[top addView: b enablingYResizing: NO];
357
[top addView: [[[NSView alloc] init] autorelease] enablingYResizing: YES];
360
b=b_useMultiCellGlyphs=[[NSButton alloc] init];
361
[b setTitle: _(@"Handle wide (multi-cell) glyphs")];
362
[b setButtonType: NSSwitchButton];
364
[top addView: b enablingYResizing: NO];
368
hb=[[GSHbox alloc] init];
369
[hb setDefaultMinXMargin: 4];
370
[hb setAutoresizingMask: NSViewWidthSizable];
372
f=[NSTextField newLabel: _(@"Bold font:")];
373
[f setAutoresizingMask: 0];
374
[hb addView: f enablingXResizing: NO];
377
f_boldTerminalFont=f=[[NSTextField alloc] init];
378
[f setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
380
[hb addView: f enablingXResizing: YES];
383
b=[[NSButton alloc] init];
384
[b setTitle: _(@"Pick font...")];
386
[b setAction: @selector(_pickBoldTerminalFont:)];
388
[hb addView: b enablingXResizing: NO];
391
[top addView: hb enablingYResizing: NO];
395
hb=[[GSHbox alloc] init];
396
[hb setDefaultMinXMargin: 4];
397
[hb setAutoresizingMask: NSViewWidthSizable];
399
f=[NSTextField newLabel: _(@"Normal font:")];
400
[f setAutoresizingMask: 0];
401
[hb addView: f enablingXResizing: NO];
404
f_terminalFont=f=[[NSTextField alloc] init];
405
[f setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
407
[hb addView: f enablingXResizing: YES];
410
b=[[NSButton alloc] init];
411
[b setTitle: _(@"Pick font...")];
413
[b setAction: @selector(_pickTerminalFont:)];
415
[hb addView: b enablingXResizing: NO];
418
[top addView: hb enablingYResizing: NO];
422
[top addView: [[[NSView alloc] init] autorelease] enablingYResizing: YES];
439
NSFontManager *fm=[NSFontManager sharedFontManager];
440
[fm setSelectedFont: [f_cur font] isMultiple: NO];
441
[fm orderFrontFontPanel: self];
444
-(void) _pickTerminalFont: (id)sender
446
f_cur=f_terminalFont;
450
-(void) _pickBoldTerminalFont: (id)sender
452
f_cur=f_boldTerminalFont;
457
TODO: The return type here should be (void), but due to forwarding issues in
458
-base, it has to be (id) to avoid a return type mismatch error
460
-(id) changeFont: (id)sender
464
if (!f_cur) return nil;
465
f=[sender convertFont: [f_cur font]];
468
[f_cur setStringValue: [NSString stringWithFormat: @"%@ %0.1f",[f fontName],[f pointSize]]];
478
*LoginShellKey=@"LoginShell",
481
static NSString *shell;
482
static BOOL loginShell;
484
@implementation TerminalViewShellPrefs
489
ud=[NSUserDefaults standardUserDefaults];
493
loginShell=[ud boolForKey: LoginShellKey];
494
shell=[ud stringForKey: ShellKey];
495
if (!shell && getenv("SHELL"))
496
shell=[NSString stringWithCString: getenv("SHELL")];
499
shell=[shell retain];
518
if ([b_loginShell state])
522
[ud setBool: loginShell forKey: LoginShellKey];
525
shell=[[tf_shell stringValue] copy];
526
[ud setObject: shell forKey: ShellKey];
531
[b_loginShell setState: loginShell];
532
[tf_shell setStringValue: shell];
541
-(void) setupButton: (NSButton *)b
543
[b setTitle: _(@"Shell")];
555
top=[[GSVbox alloc] init];
556
[top setDefaultMinYMargin: 4];
562
b=b_loginShell=[[NSButton alloc] init];
563
[b setAutoresizingMask: NSViewMinYMargin];
564
[b setTitle: _(@"Start as login-shell")];
565
[b setButtonType: NSSwitchButton];
567
[top addView: b enablingYResizing: YES];
570
tf_shell=f=[[NSTextField alloc] init];
572
[f setAutoresizingMask: NSViewWidthSizable];
573
[top addView: f enablingYResizing: NO];
576
f=[NSTextField newLabel: _(@"Shell:")];
577
[f setAutoresizingMask: NSViewMaxYMargin];
579
[top addView: f enablingYResizing: YES];
598
*CommandAsMetaKey=@"CommandAsMeta",
599
*DoubleEscapeKey=@"DoubleEscape";
601
static BOOL commandAsMeta,doubleEscape;
603
@implementation TerminalViewKeyboardPrefs
608
ud=[NSUserDefaults standardUserDefaults];
610
commandAsMeta=[ud boolForKey: CommandAsMetaKey];
611
doubleEscape=[ud boolForKey: DoubleEscapeKey];
614
+(BOOL) commandAsMeta
616
return commandAsMeta;
629
if ([b_commandAsMeta state])
633
[ud setBool: commandAsMeta forKey: CommandAsMetaKey];
635
if ([b_doubleEscape state])
639
[ud setBool: doubleEscape forKey: DoubleEscapeKey];
644
[b_commandAsMeta setState: commandAsMeta];
645
[b_doubleEscape setState: doubleEscape];
651
return _(@"Keyboard");
654
-(void) setupButton: (NSButton *)b
656
[b setTitle: _(@"Keyboard")];
668
top=[[GSVbox alloc] init];
669
[top setDefaultMinYMargin: 8];
674
b=b_commandAsMeta=[[NSButton alloc] init];
675
[b setAutoresizingMask: NSViewMinYMargin|NSViewMaxYMargin|NSViewWidthSizable];
677
_(@"Treat the command key as meta.\n"
679
@"Note that with this enabled, you won't be\n"
680
@"able to access menu entries with the\n"
682
[b setButtonType: NSSwitchButton];
684
[top addView: b enablingYResizing: YES];
689
b=b_doubleEscape=[[NSButton alloc] init];
690
[b setAutoresizingMask: NSViewMinYMargin|NSViewMaxYMargin|NSViewWidthSizable];
692
_(@"Send a double escape for the escape key.\n"
694
@"This means that the escape key will be\n"
695
@"recognized faster by many programs, but\n"
696
@"you can't use it as a substitute for meta.")];
697
[b setButtonType: NSSwitchButton];
699
[top addView: b enablingYResizing: YES];