Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: chrome/browser/resources/hterm/js/hterm.js

Issue 8680034: Initial landing of Screen, Terminal, and VT100 classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview Declares the hterm.* namespace and some basic shared utilities
7 * that are too small to deserve dedicated files.
8 */
9 var hterm = {};
10
11 /**
12 * Clamp a given integer to a specified range.
13 *
14 * @param {integer} v The value to be clamped.
15 * @param {integer} min The minimum acceptable value.
16 * @param {integer} max The maximum acceptable value.
17 */
18 hterm.clamp = function(v, min, max) {
19 if (v < min)
20 return min;
21 if (v > max)
22 return max;
23 return v;
24 };
25
26 /**
27 * Return a string containing a given number of space characters.
28 *
29 * This method maintains a static cache of the largest amount of whitespace
30 * ever requested. It shouldn't be used to generate an insanely huge amount of
31 * whitespace.
32 *
33 * @param {integer} length The desired amount of whitespace.
34 * @param {string} A string of spaces of the requested length.
35 */
36 hterm.getWhitespace = function(length) {
37 if (length == 0)
38 return '';
39
40 var f = this.getWhitespace;
41 if (!f.whitespace)
42 f.whitespace = ' ';
43
44 while (length > f.whitespace.length) {
45 f.whitespace += f.whitespace;
46 }
47
48 return f.whitespace.substr(0, length);
49 };
50
51 /**
52 * Constructor for a hterm.Size record.
53 *
54 * Instances of this class have public read/write members for width and height.
55 *
56 * @param {integer} width The width of this record.
57 * @param {integer} height The height of this record.
58 */
59 hterm.Size = function(width, height) {
60 this.width = width;
61 this.height = height;
62 };
63
64 /**
65 * Adjust the width and height of this record.
66 *
67 * @param {integer} width The new width of this record.
68 * @param {integer} height The new height of this record.
69 */
70 hterm.Size.prototype.resize = function(width, height) {
71 this.width = width;
72 this.height = height;
73 };
74
75 /**
76 * Return a copy of this record.
77 *
78 * @return {hterm.Size} A new hterm.Size instance with the same width and
79 * height.
80 */
81 hterm.Size.prototype.clone = function() {
82 return new hterm.Size(this.width, this.height);
83 };
84
85 /**
86 * Test if another hterm.Size instance is equal to this one.
87 *
88 * @param {hterm.Size} that The other hterm.Size instance.
89 * @return {boolen} True if both instances have the same width/height, false
90 * otherwise.
91 */
92 hterm.Size.prototype.equals = function(that) {
93 return this.width = that.width && this.height == that.height;
94 };
95
96 /**
97 * Return a string representation of this instance.
98 *
99 * @return {string} A string that identifies the width and height of this
100 * instance.
101 */
102 hterm.Size.prototype.toString = function() {
103 return '[hterm.Size: ' + this.width + ', ' + this.height + ']';
104 };
105
106 /**
107 * Constructor for a hterm.RowCol record.
108 *
109 * Instances of this class have public read/write members for row and column.
110 *
111 * @param {integer} row The row of this record.
112 * @param {integer} column The column of this record.
113 */
114 hterm.RowCol = function(row, column) {
115 this.row = row;
116 this.column = column;
117 };
118
119 /**
120 * Adjust the row and column of this record.
121 *
122 * @param {integer} row The new row of this record.
123 * @param {integer} column The new column of this record.
124 */
125 hterm.RowCol.prototype.move = function(row, column) {
126 this.row = row;
127 this.column = column;
128 };
129
130 /**
131 * Return a copy of this record.
132 *
133 * @return {hterm.RowCol} A new hterm.RowCol instance with the same row and
134 * column.
135 */
136 hterm.RowCol.prototype.clone = function() {
137 return new hterm.RowCol(this.row, this.column);
138 };
139
140 /**
141 * Test if another hterm.RowCol instance is equal to this one.
142 *
143 * @param {hterm.RowCol} that The other hterm.RowCol instance.
144 * @return {boolen} True if both instances have the same row/column, false
145 * otherwise.
146 */
147 hterm.RowCol.prototype.equals = function(that) {
148 return this.row = that.row && this.column == that.column;
149 };
150
151 /**
152 * Return a string representation of this instance.
153 *
154 * @return {string} A string that identifies the row and column of this
155 * instance.
156 */
157 hterm.RowCol.prototype.toString = function() {
158 return '[hterm.RowCol: ' + this.row + ', ' + this.column + ']';
159 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698