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">
|
||||
<tr>
|
||||
<td></td>
|
||||
<td class="label">{operand1}</td>
|
||||
<td class="label">{operand1Str}</td>
|
||||
<td class="bin">{operand1Binary}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{sign}</td>
|
||||
<td class="label">{operand2}</td>
|
||||
<td class="label">{operand2Str}</td>
|
||||
<td class="bin">{operand2Binary}</td>
|
||||
</tr>
|
||||
<tr class="result">
|
||||
<td>=</td>
|
||||
<td class="label">{result}</td>
|
||||
<td class="label">{resultStr}</td>
|
||||
<td class="bin">{resultBinary}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -27,8 +27,6 @@ app.set("formatter", function() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
function getBase(mode) {
|
||||
switch (mode){
|
||||
case 'bin': return 2;
|
||||
|
||||
@@ -26,6 +26,12 @@ app.run(function() {
|
||||
light: function () {
|
||||
cmdConfig.theme = 'light';
|
||||
},
|
||||
dec: function () {
|
||||
cmdConfig.mode = 'dec';
|
||||
},
|
||||
hex: function() {
|
||||
cmdConfig.mode = 'hex';
|
||||
},
|
||||
about: function() {
|
||||
var aboutResult = document.querySelector('.result .aboutTpl');
|
||||
if(aboutResult != null) {
|
||||
@@ -38,9 +44,9 @@ app.run(function() {
|
||||
|
||||
// TODO: Make as function
|
||||
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) {
|
||||
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 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.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 template = app.template(templateId)
|
||||
@@ -32,7 +37,7 @@ app.compose(function () {
|
||||
var maxLen = getBinaryLength(model.numbers);
|
||||
var table = html.element('<table class="expression"></table>');
|
||||
|
||||
model.numbers.forEach(function(o){
|
||||
model.numbers.forEach(function(n){
|
||||
|
||||
var row = table.insertRow();
|
||||
var decCell = row.insertCell();
|
||||
@@ -42,8 +47,8 @@ app.compose(function () {
|
||||
var binCell = row.insertCell();
|
||||
binCell.className = 'bin';
|
||||
|
||||
decCell.textContent = o;
|
||||
binCell.textContent = formatter.formatString(o, maxLen);
|
||||
decCell.textContent = formatter.formatString(n, cmdConfig.mode);
|
||||
binCell.textContent = formatter.padLeft(formatter.formatString(n), maxLen);
|
||||
});
|
||||
|
||||
colorizeBits(table);
|
||||
|
||||
Reference in New Issue
Block a user