mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-10 06:52:05 +01:00
Implemented support for hex and dec commands in cmd
This commit is contained in:
@@ -132,17 +132,17 @@
|
|||||||
<table class="expression">
|
<table class="expression">
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td class="label">{operand1}</td>
|
<td class="label">{operand1Str}</td>
|
||||||
<td class="bin">{operand1Binary}</td>
|
<td class="bin">{operand1Binary}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{sign}</td>
|
<td>{sign}</td>
|
||||||
<td class="label">{operand2}</td>
|
<td class="label">{operand2Str}</td>
|
||||||
<td class="bin">{operand2Binary}</td>
|
<td class="bin">{operand2Binary}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="result">
|
<tr class="result">
|
||||||
<td>=</td>
|
<td>=</td>
|
||||||
<td class="label">{result}</td>
|
<td class="label">{resultStr}</td>
|
||||||
<td class="bin">{resultBinary}</td>
|
<td class="bin">{resultBinary}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ app.set("formatter", function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getBase(mode) {
|
function getBase(mode) {
|
||||||
switch (mode){
|
switch (mode){
|
||||||
case 'bin': return 2;
|
case 'bin': return 2;
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ app.run(function() {
|
|||||||
light: function () {
|
light: function () {
|
||||||
cmdConfig.theme = 'light';
|
cmdConfig.theme = 'light';
|
||||||
},
|
},
|
||||||
|
dec: function () {
|
||||||
|
cmdConfig.mode = 'dec';
|
||||||
|
},
|
||||||
|
hex: function() {
|
||||||
|
cmdConfig.mode = 'hex';
|
||||||
|
},
|
||||||
about: function() {
|
about: function() {
|
||||||
var aboutResult = document.querySelector('.result .aboutTpl');
|
var aboutResult = document.querySelector('.result .aboutTpl');
|
||||||
if(aboutResult != null) {
|
if(aboutResult != null) {
|
||||||
@@ -38,9 +44,9 @@ app.run(function() {
|
|||||||
|
|
||||||
// TODO: Make as function
|
// TODO: Make as function
|
||||||
cmd.command({
|
cmd.command({
|
||||||
canHandle: function(input) { return app.get('expression').canParse(input); },
|
canHandle: function(input) { return app.get('expression').canParse(input, cmdConfig.mode); },
|
||||||
handle: function(input) {
|
handle: function(input) {
|
||||||
return app.get('expression').parse(input);
|
return app.get('expression').parse(input, cmdConfig.mode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,15 @@ app.compose(function () {
|
|||||||
var maxLen = getBinaryLength([expr.operand1, expr.operand2, result]);
|
var maxLen = getBinaryLength([expr.operand1, expr.operand2, result]);
|
||||||
|
|
||||||
var model = Object.create(expr);
|
var model = Object.create(expr);
|
||||||
model.result = result;
|
|
||||||
|
model.resultStr = formatter.formatString(result, cmdConfig.mode);
|
||||||
|
model.operand1Str = formatter.formatString(expr.operand1, cmdConfig.mode);
|
||||||
|
model.operand2Str = formatter.formatString(expr.operand2, cmdConfig.mode);
|
||||||
model.operand1Binary = formatter.padLeft(formatter.formatString(expr.operand1), maxLen);
|
model.operand1Binary = formatter.padLeft(formatter.formatString(expr.operand1), maxLen);
|
||||||
model.operand2Binary = formatter.padLeft(formatter.formatString(expr.operand2), maxLen);
|
model.operand2Binary = formatter.padLeft(formatter.formatString(expr.operand2), maxLen);
|
||||||
model.resultBinary = formatter.padLeft(formatter.formatString(result), maxLen);
|
model.resultBinary = formatter.padLeft(formatter.formatString(result, cmdConfig.mode), maxLen);
|
||||||
|
|
||||||
|
console.log(model);
|
||||||
|
|
||||||
var templateId = /<<|>>/.test(model.sign) ? 'shiftExpressionView' : 'binaryExpressionView';
|
var templateId = /<<|>>/.test(model.sign) ? 'shiftExpressionView' : 'binaryExpressionView';
|
||||||
var template = app.template(templateId)
|
var template = app.template(templateId)
|
||||||
@@ -32,7 +37,7 @@ app.compose(function () {
|
|||||||
var maxLen = getBinaryLength(model.numbers);
|
var maxLen = getBinaryLength(model.numbers);
|
||||||
var table = html.element('<table class="expression"></table>');
|
var table = html.element('<table class="expression"></table>');
|
||||||
|
|
||||||
model.numbers.forEach(function(o){
|
model.numbers.forEach(function(n){
|
||||||
|
|
||||||
var row = table.insertRow();
|
var row = table.insertRow();
|
||||||
var decCell = row.insertCell();
|
var decCell = row.insertCell();
|
||||||
@@ -42,8 +47,8 @@ app.compose(function () {
|
|||||||
var binCell = row.insertCell();
|
var binCell = row.insertCell();
|
||||||
binCell.className = 'bin';
|
binCell.className = 'bin';
|
||||||
|
|
||||||
decCell.textContent = o;
|
decCell.textContent = formatter.formatString(n, cmdConfig.mode);
|
||||||
binCell.textContent = formatter.formatString(o, maxLen);
|
binCell.textContent = formatter.padLeft(formatter.formatString(n), maxLen);
|
||||||
});
|
});
|
||||||
|
|
||||||
colorizeBits(table);
|
colorizeBits(table);
|
||||||
|
|||||||
Reference in New Issue
Block a user